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

Nav Accessibility: Expose focus public method so that caller can explicitly set focus to Nav component. #10310

Merged
merged 7 commits into from
Aug 30, 2019

Conversation

inateeg
Copy link
Collaborator

@inateeg inateeg commented Aug 29, 2019

Pull request checklist

  • Addresses an existing issue: Fixes #0000
  • Include a change request file using $ yarn change

When Nav component is rendered, there is property 'isOnTop' can by passed in when the Nav is rendered as popup. IN SPO case, this is when in T-narrow mode, Nav is only rendered when user click on Hamburg. Under this condition, we would like Nav get focus since it is intentionally popup opened by user action. This PR ensure when those conditions meet, Nav focusZone get focus so user can use arrow key to navigate through nodes.

(give an overview)

Focus areas to test

set isOnTop to true and verify the arrow key can navigate through the nav nodes while without this property set, that is not possible.

Microsoft Reviewers: Open in CodeFlow

@@ -33,16 +34,29 @@ export class NavBase extends React.Component<INavProps, INavState> implements IN
groups: null
};

private _focusZone: IFocusZone | null;
Copy link
Member

Choose a reason for hiding this comment

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

Use React.createRef();

@@ -55,7 +69,8 @@ export class NavBase extends React.Component<INavProps, INavState> implements IN
const classNames = getClassNames(styles!, { theme: theme!, className, isOnTop, groups });

return (
<FocusZone direction={FocusZoneDirection.vertical}>
// tslint:disable-next-line: jsx-no-lambda
<FocusZone direction={FocusZoneDirection.vertical} componentRef={focusZone => (this._focusZone = focusZone)}>
Copy link
Member

Choose a reason for hiding this comment

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

no need to pass in a function; just use createRef.

@@ -67,6 +82,13 @@ export class NavBase extends React.Component<INavProps, INavState> implements IN
return this.state.selectedKey;
}

private _setNavWithFocus() {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is the right thing to do and makes me really confused.

If you want to expose a focus method on Nav, and direct it to the focuszone.focus, that would make sense.

As this is I would not have expected this behavior as a user.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it is not the idea solution for sure and Ping and I discussed and found if isOnTop already there we might be able to use it so there will be no change in SP pages since it always set isOnTop for this condition.

We tried to do it in wrapper comp but simply Nav is not focus-able. We will explore to see if expose focuse method on Nav object perhaps be better fit?

@dzearing
Copy link
Member

Also in the future please title your PRs with meaningful names, it helps identify it at a glance. :)

@dzearing dzearing changed the title Inateeg/0828nav new Nav: when isOnTop is true, set focus immediately Aug 29, 2019
Copy link
Member

@dzearing dzearing left a comment

Choose a reason for hiding this comment

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

I really don't believe this is the right fix. No component should force focus onto an element unless the prop is named something like "autoFocus" or "setInitialFocus".

A better approach would be to expose a focus imperative method which you can call at the right time.

@inateeg inateeg changed the title Nav: when isOnTop is true, set focus immediately Nav Accessibility: using isOnTop property to ensure focus on popup Nav Aug 29, 2019
@inateeg
Copy link
Collaborator Author

inateeg commented Aug 29, 2019 via email

@inateeg inateeg changed the title Nav Accessibility: using isOnTop property to ensure focus on popup Nav Nav Accessibility: Expose focus public method so that caller can explicitly set focus to Nav component. Aug 29, 2019
@size-auditor
Copy link

size-auditor bot commented Aug 29, 2019

Asset size changes

Project Bundle Baseline Size New Size Difference
office-ui-fabric-react Nav 174.724 kB 174.923 kB ExceedsBaseline     199 bytes

ExceedsTolerance Over Tolerance (1024 B) ExceedsBaseline Over Baseline BelowBaseline Below Baseline New New Deleted  Removed 1 kB = 1000 B

Baseline commit: 17e5e3ab7c6b049cc1e1bd4a7126f9f3988e8f4c (build)

@msft-github-bot
Copy link
Contributor

msft-github-bot commented Aug 29, 2019

Component Perf Analysis

No significant results to display.

All results

Scenario Master Ticks PR Ticks Status
BaseButton 781 765
BaseButton (experiments) 952 1003
DefaultButton 1048 1027
DefaultButton (experiments) 1905 1871
DetailsRow 3254 3310
DetailsRow (fast icons) 3194 3231
DetailsRow without styles 3076 3039
DocumentCardTitle with truncation 30719 30844
MenuButton 1293 1403
MenuButton (experiments) 3483 3430
PrimaryButton 1180 1235
PrimaryButton (experiments) 1992 2010
SplitButton 2742 2777
SplitButton (experiments) 6925 6889
Stack 490 466
Stack with Intrinsic children 1112 1101
Stack with Text children 4206 4157
Text 381 377
Toggle 826 864
Toggle (experiments) 2238 2231
button 63 53

Copy link
Member

@dzearing dzearing left a comment

Choose a reason for hiding this comment

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

Minor nit; can you remove the example tweak? Otherwise looks good!

@Vitalius1 Vitalius1 merged commit d1ef1ac into microsoft:master Aug 30, 2019
@msft-github-bot
Copy link
Contributor

🎉office-ui-fabric-react@v7.29.0 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants