Skip to content

fix: check for element visibility should take react aria attribute into consideration #8642

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 3 commits into from
Aug 7, 2025
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
4 changes: 2 additions & 2 deletions packages/@react-aria/utils/src/isElementVisible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ function isAttributeVisible(element: Element, childElement?: Element) {
*/
export function isElementVisible(element: Element, childElement?: Element): boolean {
if (supportsCheckVisibility) {
return element.checkVisibility();
return element.checkVisibility() && !element.closest('[data-react-aria-prevent-focus]');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not convinced this is where the check should be given the name of the function vs the name of the attribute...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this is a bit confusing cuz of the naming, but if I understand this correctly, this is to make it so isTabbable/isFocusable don't resolve as true for elements with the above data attribute correct? Any reason we don't move this check into those functions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be annoying to do it there because you have to check all the parents as well. I think it's ok here for now

}

return (
element.nodeName !== '#comment' &&
isStyleVisible(element) &&
Expand Down
51 changes: 50 additions & 1 deletion packages/react-aria-components/stories/Toolbar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
* governing permissions and limitations under the License.
*/

import {Checkbox, Link, ToggleButton, Toolbar, ToolbarProps} from 'react-aria-components';
import {Button, Checkbox, Group, Label, Link, ListBox, Popover, Select, SelectValue, Separator, ToggleButton, Toolbar, ToolbarProps} from 'react-aria-components';
import {classNames} from '@react-spectrum/utils';
import {Meta, StoryObj} from '@storybook/react';
import {MyListBoxItem} from './utils';
import {Orientation} from 'react-stately';
import React from 'react';
import styles from '../example/index.css';
Expand Down Expand Up @@ -56,3 +57,51 @@ export const ToolbarExample: ToolbarStory = {
);
}
};

export const SelectSupport: ToolbarStory = {
args: {
orientation: 'horizontal' as Orientation
},
render: (props: ToolbarProps) => {
return (
<Toolbar {...props} aria-label="Text formatting">
<Group aria-label="Style">
<ToggleButton aria-label="Bold">
<b>B</b>
</ToggleButton>
<ToggleButton aria-label="Italic">
<i>I</i>
</ToggleButton>
<ToggleButton aria-label="Underline">
<u>U</u>
</ToggleButton>
</Group>
<Separator orientation="vertical" />
<Select>
<Label>Favorite Animal</Label>
<Button>
<SelectValue />
<span aria-hidden="true">▼</span>
</Button>
<Popover>
<ListBox>
<MyListBoxItem>Aardvark</MyListBoxItem>
<MyListBoxItem>Cat</MyListBoxItem>
<MyListBoxItem>Dog</MyListBoxItem>
<MyListBoxItem>Kangaroo</MyListBoxItem>
<MyListBoxItem>Panda</MyListBoxItem>
<MyListBoxItem>Snake</MyListBoxItem>
</ListBox>
</Popover>
</Select>
<Separator orientation="vertical" />

<Group aria-label="Clipboard">
<Button>Copy</Button>
<Button>Paste</Button>
<Button>Cut</Button>
</Group>
</Toolbar>
);
}
};