Skip to content

Commit

Permalink
BUGFIX: Render dropdown contents even when dropdown is closed
Browse files Browse the repository at this point in the history
Until now, dropdown contents were `null`ed when the dropdown is closed.
This leads to unneccessary re-renders every time the dropdown visibility
is toggled.

This commit changes this logic. Dropdown contents are now always
rendered, but hidden when the dropdown is closed.
  • Loading branch information
grebaldi committed May 30, 2024
1 parent 9cf9b88 commit 5666f1d
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions packages/react-ui-components/src/DropDown/contents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,25 +214,22 @@ export default class ShallowDropDownContents extends PureComponent<ShallowDropDo
}
);

if (isOpen) {
const contents = (
<ul
className={finalClassName}
aria-hidden={isOpen ? 'false' : 'true'}
aria-label="dropdown"
role="listbox"
onClick={closeDropDown}
style={this.state.style}
data-ignore_click_outside={true}
>
{children}
</ul>
);

return scrollable
? ReactDOM.createPortal(contents, document.body)
: contents;
}
return null;
const contents = (
<ul
className={finalClassName}
aria-hidden={isOpen ? 'false' : 'true'}
aria-label="dropdown"
role="listbox"
onClick={closeDropDown}
style={this.state.style}
data-ignore_click_outside={true}
>
{children}
</ul>
);

return scrollable
? ReactDOM.createPortal(contents, document.body)
: contents;
}
}

0 comments on commit 5666f1d

Please sign in to comment.