mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-01 03:29:39 +08:00
fix: Invalid regular expression for particular ellipsis content (#27383)
* fix: Invalid regular expression for particular ellipsis content * fix: ellipsisContent is possibly nullable * test: add test cases for ellipsis string with parentheses
This commit is contained in:
parent
74bbe8e4e3
commit
07d4022e18
@ -472,7 +472,7 @@ class Base extends React.Component<InternalBlockProps, BaseState> {
|
||||
}
|
||||
|
||||
// show rest content as title on symbol
|
||||
restContent = restContent?.replace(new RegExp(`^${ellipsisContent}`), '');
|
||||
restContent = restContent?.slice(String(ellipsisContent || '').length);
|
||||
|
||||
// We move full content to outer element to avoid repeat read the content by accessibility
|
||||
textNode = (
|
||||
|
@ -104,6 +104,41 @@ describe('Typography', () => {
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
it('string with parentheses', async () => {
|
||||
const parenthesesStr = `Ant Design, a design language (for background applications, is refined by
|
||||
Ant UED Team. Ant Design, a design language for background applications,
|
||||
is refined by Ant UED Team. Ant Design, a design language for background
|
||||
applications, is refined by Ant UED Team. Ant Design, a design language
|
||||
for background applications, is refined by Ant UED Team. Ant Design, a
|
||||
design language for background applications, is refined by Ant UED Team.
|
||||
Ant Design, a design language for background applications, is refined by
|
||||
Ant UED Team.`;
|
||||
const onEllipsis = jest.fn();
|
||||
const wrapper = mount(
|
||||
<Base ellipsis={{ onEllipsis }} component="p" editable>
|
||||
{parenthesesStr}
|
||||
</Base>,
|
||||
);
|
||||
|
||||
await sleep(20);
|
||||
wrapper.update();
|
||||
expect(wrapper.text()).toEqual('Ant Design, a des...');
|
||||
const ellipsisSpan = wrapper.find('span[title]');
|
||||
expect(ellipsisSpan.text()).toEqual('...');
|
||||
expect(ellipsisSpan.props().title)
|
||||
.toEqual(`ign language (for background applications, is refined by
|
||||
Ant UED Team. Ant Design, a design language for background applications,
|
||||
is refined by Ant UED Team. Ant Design, a design language for background
|
||||
applications, is refined by Ant UED Team. Ant Design, a design language
|
||||
for background applications, is refined by Ant UED Team. Ant Design, a
|
||||
design language for background applications, is refined by Ant UED Team.
|
||||
Ant Design, a design language for background applications, is refined by
|
||||
Ant UED Team.`);
|
||||
onEllipsis.mockReset();
|
||||
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
it('should middle ellipsis', async () => {
|
||||
const suffix = '--suffix';
|
||||
const wrapper = mount(
|
||||
|
Loading…
Reference in New Issue
Block a user