Skip to content
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

fix: react-popover compatibility with screen reader #28172

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

emmayjiang
Copy link
Contributor

Allows the popover created by react-popover to be read by screen readers despite having no focusable content.

@emmayjiang emmayjiang requested a review from a team as a code owner June 7, 2023 18:30
@fabricteam
Copy link
Collaborator

fabricteam commented Jun 7, 2023

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
211.151 kB
58.715 kB
211.165 kB
58.722 kB
14 B
7 B
react-infobutton
InfoButton
132.502 kB
40.405 kB
132.516 kB
40.411 kB
14 B
6 B
react-infobutton
InfoLabel
135.967 kB
41.466 kB
135.981 kB
41.472 kB
14 B
6 B
react-popover
Popover
119.464 kB
36.745 kB
119.478 kB
36.751 kB
14 B
6 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-alert
Alert
93.624 kB
22.563 kB
react-avatar
Avatar
57.872 kB
15.115 kB
react-avatar
AvatarGroup
15.682 kB
6.306 kB
react-avatar
AvatarGroupItem
74.048 kB
19.605 kB
react-components
react-components: Button, FluentProvider & webLightTheme
64.935 kB
17.918 kB
react-components
react-components: FluentProvider & webLightTheme
36.168 kB
11.964 kB
react-datepicker-compat
DatePicker Compat
222.522 kB
59.185 kB
react-persona
Persona
64.793 kB
17.036 kB
react-portal-compat
PortalCompatProvider
6.473 kB
2.196 kB
react-table
DataGrid
150.941 kB
41.535 kB
react-table
Table (Primitives only)
45.147 kB
12.577 kB
react-table
Table as DataGrid
133.392 kB
34.008 kB
react-table
Table (Selection only)
79.161 kB
19.386 kB
react-table
Table (Sort only)
78.491 kB
19.195 kB
react-tags
Tag
22.04 kB
7.94 kB
🤖 This report was generated against 517b807cd97ee89a470ac5e9dec48a6f42b69532

@@ -45,10 +46,13 @@ export const usePopoverSurface_unstable = (
root: 'div',
},
root: getNativeElementProps('div', {
id,
'aria-labelledby': id,
Copy link
Contributor

Choose a reason for hiding this comment

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

ah sorry, I think I forgot to mention -- I think the id + aria-labelledby should go in the examples, rather than in the base component. The reason is that I think having a popover be labelled by all its content is too opinionated as a default. It works well for small popovers like our examples, but not for longer popovers (which should probably be labelled just by the title).

We'll add docs about how to properly label, but for now I think this bit should be in the examples

@fabricteam
Copy link
Collaborator

fabricteam commented Jun 7, 2023

Perf Analysis (@fluentui/react-components)

Scenario Render type Master Ticks PR Ticks Iterations Status
FluentProviderWithTheme mount 81 86 10 Possible regression
All results

Scenario Render type Master Ticks PR Ticks Iterations Status
Avatar mount 588 580 5000
Button mount 303 296 5000
Field mount 1056 1025 5000
FluentProvider mount 640 654 5000
FluentProviderWithTheme mount 81 86 10 Possible regression
FluentProviderWithTheme virtual-rerender 74 74 10
FluentProviderWithTheme virtual-rerender-with-unmount 76 77 10
InfoButton mount 17 13 5000
MakeStyles mount 863 862 50000
Persona mount 1592 1605 5000
SpinButton mount 1238 1272 5000

@size-auditor
Copy link

size-auditor bot commented Jun 7, 2023

Asset size changes

Size Auditor did not detect a change in bundle size for any component!

Baseline commit: 517b807cd97ee89a470ac5e9dec48a6f42b69532 (build)

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 7, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 061fc3e:

Sandbox Source
@fluentui/react 8 starter Configuration
@fluentui/react-components 9 starter Configuration

@fabricteam
Copy link
Collaborator

fabricteam commented Jun 7, 2023

🕵 fluentuiv9 No visual regressions between this PR and main

@sopranopillow sopranopillow assigned emmayjiang and unassigned Hotell Jun 7, 2023
@@ -49,6 +49,7 @@ export const usePopoverSurface_unstable = (
role: trapFocus ? 'dialog' : 'group',
'aria-modal': trapFocus ? true : undefined,
...modalAttributes,
tabIndex: '-1',
Copy link
Member

Choose a reason for hiding this comment

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

in cases where popovers don't contain focusable elemnts, wouldn't users just be able to use inline?

There's nothing in this component that will actually focus this element if it's open. Unless the conclusion behind this PR is that we should be doing that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@smhigley probably has more insight to share

Copy link
Contributor

Choose a reason for hiding this comment

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

@ling1726 the popover does actually get focus when tabIndex="-1" is present -- my assumption was that tabster was doing that 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

PopoverSurface gets focus when tabIndex=-1 because of this useEffect

const firstFocusable = isNaN(containerTabIndex)

Copy link
Member

Choose a reason for hiding this comment

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

When the popover was built, we never expected the focusing effect to work when users don't put focusable elements inside popovers. Our guidance has always been to treat popovers as dialogs when this happens use trapFocus in that case.

@smhigley if popovers have no focusable content, would inline be enough? if we result to focusing the entire popover by default always, I don't see a reason to use inline

@smhigley
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 4 pipeline(s).

@emmayjiang emmayjiang force-pushed the react-popover-screenreader-fix branch from 21b5773 to 061fc3e Compare June 13, 2023 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants