Skip to content

fix(Toolbar): make ids unique for overflow items #4557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/main/src/components/Toolbar/OverflowPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ export const OverflowPopover: FC<OverflowPopoverProps> = (props: OverflowPopover
<div className={classes.popoverContent} ref={overflowContentRef}>
{children.map((item, index) => {
if (index > lastVisibleIndex && index > numberOfAlwaysVisibleItems - 1) {
// @ts-expect-error: if props is not defined, it doesn't have an id (is not a ReactElement)
if (item?.props?.id) {
// @ts-expect-error: item is ReactElement
return cloneElement(item, { id: `${item.props.id}-overflow` });
}
// @ts-expect-error: if type is not defined, it's not a spacer
if (item.type?.displayName === 'ToolbarSeparator') {
return cloneElement(item as ReactElement, {
Expand Down
17 changes: 17 additions & 0 deletions packages/main/src/components/Toolbar/Toolbar.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,23 @@ describe('Toolbar', () => {
cy.findByTestId('tb').should('have.css', 'boxShadow', 'rgb(0, 112, 242) 0px 0px 0px 2px inset');
});

it('unique ids for overflow', () => {
cy.viewport(100, 500);
cy.mount(
<Toolbar>
<div id="1">Text1</div>
<div>Text2 no id</div>
<Button id="3">Text4</Button>
</Toolbar>
);

cy.get('#1').should('have.length', 1);
cy.get('#1-overflow').should('have.length', 1);
cy.findAllByText('Text2 no id').should('have.length', 2).and('not.have.attr', 'id');
cy.get('#3').should('have.length', 1);
cy.get('#3-overflow').should('have.length', 1);
});

mountWithCustomTagName(Toolbar);
cypressPassThroughTestsFactory(Toolbar);
});