Skip to content

Commit 7d8e3ab

Browse files
authored
fix(Toolbar): make ids unique for overflow items (#4557)
Fixes #4556
1 parent decc9e0 commit 7d8e3ab

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

packages/main/src/components/Toolbar/OverflowPopover.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ export const OverflowPopover: FC<OverflowPopoverProps> = (props: OverflowPopover
129129
<div className={classes.popoverContent} ref={overflowContentRef}>
130130
{children.map((item, index) => {
131131
if (index > lastVisibleIndex && index > numberOfAlwaysVisibleItems - 1) {
132+
// @ts-expect-error: if props is not defined, it doesn't have an id (is not a ReactElement)
133+
if (item?.props?.id) {
134+
// @ts-expect-error: item is ReactElement
135+
return cloneElement(item, { id: `${item.props.id}-overflow` });
136+
}
132137
// @ts-expect-error: if type is not defined, it's not a spacer
133138
if (item.type?.displayName === 'ToolbarSeparator') {
134139
return cloneElement(item as ReactElement, {

packages/main/src/components/Toolbar/Toolbar.cy.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,23 @@ describe('Toolbar', () => {
535535
cy.findByTestId('tb').should('have.css', 'boxShadow', 'rgb(0, 112, 242) 0px 0px 0px 2px inset');
536536
});
537537

538+
it('unique ids for overflow', () => {
539+
cy.viewport(100, 500);
540+
cy.mount(
541+
<Toolbar>
542+
<div id="1">Text1</div>
543+
<div>Text2 no id</div>
544+
<Button id="3">Text4</Button>
545+
</Toolbar>
546+
);
547+
548+
cy.get('#1').should('have.length', 1);
549+
cy.get('#1-overflow').should('have.length', 1);
550+
cy.findAllByText('Text2 no id').should('have.length', 2).and('not.have.attr', 'id');
551+
cy.get('#3').should('have.length', 1);
552+
cy.get('#3-overflow').should('have.length', 1);
553+
});
554+
538555
mountWithCustomTagName(Toolbar);
539556
cypressPassThroughTestsFactory(Toolbar);
540557
});

0 commit comments

Comments
 (0)