Skip to content

Commit

Permalink
Do not render Popover children while closed
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Nov 22, 2024
1 parent 3021966 commit 505c800
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/components/feedback/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export default function Popover({
data-testid="popover"
data-component="Popover"
>
{children}
{open && children}
</div>
);
}
23 changes: 11 additions & 12 deletions src/components/feedback/test/Popover-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ function FakeComponent({ children, ...rest }) {
Anchor element
</button>
<Popover open={open} anchorElementRef={buttonRef} {...rest}>
{open &&
(children ?? (
<>
Content of popover
<button
data-testid="inner-button"
onClick={() => setOpen(prev => !prev)}
>
Focusable element inside popover
</button>
</>
))}
{children ?? (
<>
Content of popover
<button
data-testid="inner-button"
onClick={() => setOpen(prev => !prev)}
>
Focusable element inside popover
</button>
</>
)}
</Popover>
</div>
);
Expand Down
3 changes: 1 addition & 2 deletions src/components/input/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,9 @@ function SelectMain<T>({
aria-multiselectable={multiple}
aria-labelledby={buttonId ?? defaultButtonId}
aria-orientation="vertical"
data-listbox-open={listboxOpen}
onScroll={onListboxScroll}
>
{listboxOpen && children}
{children}
</ul>
</Popover>
</SelectContext.Provider>
Expand Down
2 changes: 1 addition & 1 deletion src/components/input/test/Select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('Select', () => {
const toggleListbox = wrapper => getToggleButton(wrapper).simulate('click');

const isListboxClosed = wrapper =>
wrapper.find('[role="listbox"]').prop('data-listbox-open') === false;
wrapper.find('Popover').prop('open') === false;

const openListbox = wrapper => {
if (isListboxClosed(wrapper)) {
Expand Down

0 comments on commit 505c800

Please sign in to comment.