-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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: remove aria-current from navLink when inactive #5508
fix: remove aria-current from navLink when inactive #5508
Conversation
@timdorr Nice change to pass all the allowed values through! Actually because it is a camelCase prop I did not even think it was part of the component interface, sorry! Can I change it to accept the The following change would allow the prop to be passed as What do you think?
|
@AlmeroSteyn It's your PR, you can make any changes that you'd like 😉. I would recommend adding a couple of tests just to verify the behavior. One where the |
…d add valid values
@pshrmn I changed the prop to kebab-case and added values And added the tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems good to me.
For anyone interested, using aria-*
in JSX is documented in the accessibility docs. While a <NavLink>
isn't a native component, I think that it makes sense to make its ARIA prop consistent with <input>
, et al.
@@ -50,12 +50,12 @@ NavLink.propTypes = { | |||
activeStyle: PropTypes.object, | |||
style: PropTypes.object, | |||
isActive: PropTypes.func, | |||
ariaCurrent: PropTypes.oneOf(['page', 'step', 'location', 'true']) | |||
'aria-current': PropTypes.oneOf(['page', 'step', 'location', 'date', 'time', 'true']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should be worrying about all the possible values and just doing a string type here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current standard confix for create-react-app
includes the eslint-plugin-jsx-a11y
rule jsx-a11y/aria-proptypes
activated by default. It already validates all aria-*
values which, in this case, shows the following warning message for this rule at compile time:
The value for aria-current must be a single token from the following: page,step,location,date,time,true,false
So I agree that this is redundant. Better to have such a dedicated library worry about these details.
Shall I remove it?
LGTM |
Weird, had to do it twice... Something's up with Github. Anyways, this should be good to go. Will merge when it goes green. |
Thank you for merging this! |
179: Update dependency react-router-dom to v4.3.0 r=magopian a=renovate[bot] This Pull Request updates dependency [react-router-dom](https://github.com/ReactTraining/react-router) from `v4.2.2` to `v4.3.0` <details> <summary>Release Notes</summary> ### [`v4.3.0`](https://github.com/ReactTraining/react-router/blob/master/CHANGELOG.md#v430httpsgithubcomReactTrainingreact-routercomparev420v430) [Compare Source](remix-run/react-router@v4.3.0-rc.3...a27bc56) > Jun 6, 2018 * Use the `pretty` option in generatePath ([#​6172] by @​sibelius) * aria-current has incorrect value "true" ([#​6118] by @​brandonrninefive) * Redirect with parameters ([#​5209] by @​dlindenkreuz) * Fix with missing pathname: `<Link to="?foo=bar">` ([#​5489] by @​pshrmn) * Escape NavLink path to allow special characters in path. ([#​5596] by @​esiegel) * Expose `generatePath` ([#​5661] by @​rybon) * Use named import of history module. ([#​5589] by @​RoboBurned) * Hoist dependencies for smaller UMD builds ([#​5720] by @​pshrmn) * Remove aria-current from navLink when inactive ([#​5508] by @​AlmeroSteyn) * Add invariant for missing "to" property on `<Link>` ([#​5792] by @​selbekk) * Use Prettier on the code ([e6f9017] by @​mjackson) * Fix pathless route's match when parent is null ([#​5964] by @​pshrmn) * Use history.createLocation in `<StaticRouter>` ([#​5722] by @​pshrmn) [#​6172]: `https://github.com/ReactTraining/react-router/pull/6172` [#​6118]: `https://github.com/ReactTraining/react-router/pull/6118` [#​5209]: `https://github.com/ReactTraining/react-router/pull/5209` [#​5489]: `https://github.com/ReactTraining/react-router/pull/5489` [#​5596]: `https://github.com/ReactTraining/react-router/pull/5596` [#​5661]: `https://github.com/ReactTraining/react-router/pull/5661` [#​5589]: `https://github.com/ReactTraining/react-router/pull/5589` [#​5720]: `https://github.com/ReactTraining/react-router/pull/5720` [#​5508]: `https://github.com/ReactTraining/react-router/pull/5508` [#​5792]: `https://github.com/ReactTraining/react-router/pull/5792` [e6f9017]: remix-run/react-router@e6f9017 [#​5964]: `https://github.com/ReactTraining/react-router/pull/5964` [#​5722]: `https://github.com/ReactTraining/react-router/pull/5722` --- ### [`v4.3.0-rc.3`](https://github.com/ReactTraining/react-router/releases/v4.3.0-rc.3) [Compare Source](remix-run/react-router@v4.3.0-rc.2...v4.3.0-rc.3) - Fix broken UMD builds. - Add sideEffects: false for webpack tree shaking (#​6082 by @​taylorc93) --- ### [`v4.3.0-rc.2`](https://github.com/ReactTraining/react-router/releases/v4.3.0-rc.2) [Compare Source](remix-run/react-router@v4.3.0-rc.1...v4.3.0-rc.2) - Bump `hoist-non-react-statics` for React 16.3. - Missing `generatePath` in `react-router-dom` package. --- ### [`v4.3.0-rc.1`](https://github.com/ReactTraining/react-router/releases/v4.3.0-rc.1) [Compare Source](remix-run/react-router@v4.2.2...v4.3.0-rc.1) > Mar 26, 2018 - Redirect with parameters ([#​5209] by @​dlindenkreuz) - Fix with missing pathname: `<Link to="?foo=bar">` ([#​5489] by @​pshrmn) - Escape NavLink path to allow special characters in path. ([#​5596] by @​esiegel) - Expose `generatePath` ([#​5661] by @​rybon) - Use named import of history module. ([#​5589] by @​RoboBurned) - Hoist dependencies for smaller UMD builds ([#​5720] by @​pshrmn) - Remove aria-current from navLink when inactive ([#​5508] by @​AlmeroSteyn) - Add invariant for missing "to" property on `<Link>` ([#​5792] by @​selbekk) - Use Prettier on the code ([e6f9017] by @​mjackson) - Fix pathless route's match when parent is null ([#​5964] by @​pshrmn) - Use history.createLocation in `<StaticRouter>` ([#​5722] by @​pshrmn) [#​5209]: `https://github.com/ReactTraining/react-router/pull/5209` [#​5489]: `https://github.com/ReactTraining/react-router/pull/5489` [#​5596]: `https://github.com/ReactTraining/react-router/pull/5596` [#​5661]: `https://github.com/ReactTraining/react-router/pull/5661` [#​5589]: `https://github.com/ReactTraining/react-router/pull/5589` [#​5720]: `https://github.com/ReactTraining/react-router/pull/5720` [#​5508]: `https://github.com/ReactTraining/react-router/pull/5508` [#​5792]: `https://github.com/ReactTraining/react-router/pull/5792` [e6f9017]: remix-run/react-router@e6f9017 [#​5964]: `https://github.com/ReactTraining/react-router/pull/5964` [#​5722]: `https://github.com/ReactTraining/react-router/pull/5722` --- </details> --- This PR has been generated by [Renovate Bot](https://renovatebot.com). Co-authored-by: Renovate Bot <[email protected]>
178: Update dependency react-router to v4.3.0 r=magopian a=renovate[bot] This Pull Request updates dependency [react-router](https://github.com/ReactTraining/react-router) from `v4.2.0` to `v4.3.0` <details> <summary>Release Notes</summary> ### [`v4.3.0`](https://github.com/ReactTraining/react-router/blob/master/CHANGELOG.md#v430httpsgithubcomReactTrainingreact-routercomparev420v430) [Compare Source](remix-run/react-router@v4.3.0-rc.3...v4.3.0) > Jun 6, 2018 * Use the `pretty` option in generatePath ([#​6172] by @​sibelius) * aria-current has incorrect value "true" ([#​6118] by @​brandonrninefive) * Redirect with parameters ([#​5209] by @​dlindenkreuz) * Fix with missing pathname: `<Link to="?foo=bar">` ([#​5489] by @​pshrmn) * Escape NavLink path to allow special characters in path. ([#​5596] by @​esiegel) * Expose `generatePath` ([#​5661] by @​rybon) * Use named import of history module. ([#​5589] by @​RoboBurned) * Hoist dependencies for smaller UMD builds ([#​5720] by @​pshrmn) * Remove aria-current from navLink when inactive ([#​5508] by @​AlmeroSteyn) * Add invariant for missing "to" property on `<Link>` ([#​5792] by @​selbekk) * Use Prettier on the code ([e6f9017] by @​mjackson) * Fix pathless route's match when parent is null ([#​5964] by @​pshrmn) * Use history.createLocation in `<StaticRouter>` ([#​5722] by @​pshrmn) [#​6172]: `https://github.com/ReactTraining/react-router/pull/6172` [#​6118]: `https://github.com/ReactTraining/react-router/pull/6118` [#​5209]: `https://github.com/ReactTraining/react-router/pull/5209` [#​5489]: `https://github.com/ReactTraining/react-router/pull/5489` [#​5596]: `https://github.com/ReactTraining/react-router/pull/5596` [#​5661]: `https://github.com/ReactTraining/react-router/pull/5661` [#​5589]: `https://github.com/ReactTraining/react-router/pull/5589` [#​5720]: `https://github.com/ReactTraining/react-router/pull/5720` [#​5508]: `https://github.com/ReactTraining/react-router/pull/5508` [#​5792]: `https://github.com/ReactTraining/react-router/pull/5792` [e6f9017]: remix-run/react-router@e6f9017 [#​5964]: `https://github.com/ReactTraining/react-router/pull/5964` [#​5722]: `https://github.com/ReactTraining/react-router/pull/5722` --- ### [`v4.3.0-rc.3`](https://github.com/ReactTraining/react-router/releases/v4.3.0-rc.3) [Compare Source](remix-run/react-router@v4.3.0-rc.2...v4.3.0-rc.3) - Fix broken UMD builds. - Add sideEffects: false for webpack tree shaking (#​6082 by @​taylorc93) --- ### [`v4.3.0-rc.2`](https://github.com/ReactTraining/react-router/releases/v4.3.0-rc.2) [Compare Source](remix-run/react-router@v4.3.0-rc.1...v4.3.0-rc.2) - Bump `hoist-non-react-statics` for React 16.3. - Missing `generatePath` in `react-router-dom` package. --- ### [`v4.3.0-rc.1`](https://github.com/ReactTraining/react-router/releases/v4.3.0-rc.1) [Compare Source](remix-run/react-router@v4.2.0...v4.3.0-rc.1) > Mar 26, 2018 - Redirect with parameters ([#​5209] by @​dlindenkreuz) - Fix with missing pathname: `<Link to="?foo=bar">` ([#​5489] by @​pshrmn) - Escape NavLink path to allow special characters in path. ([#​5596] by @​esiegel) - Expose `generatePath` ([#​5661] by @​rybon) - Use named import of history module. ([#​5589] by @​RoboBurned) - Hoist dependencies for smaller UMD builds ([#​5720] by @​pshrmn) - Remove aria-current from navLink when inactive ([#​5508] by @​AlmeroSteyn) - Add invariant for missing "to" property on `<Link>` ([#​5792] by @​selbekk) - Use Prettier on the code ([e6f9017] by @​mjackson) - Fix pathless route's match when parent is null ([#​5964] by @​pshrmn) - Use history.createLocation in `<StaticRouter>` ([#​5722] by @​pshrmn) [#​5209]: `https://github.com/ReactTraining/react-router/pull/5209` [#​5489]: `https://github.com/ReactTraining/react-router/pull/5489` [#​5596]: `https://github.com/ReactTraining/react-router/pull/5596` [#​5661]: `https://github.com/ReactTraining/react-router/pull/5661` [#​5589]: `https://github.com/ReactTraining/react-router/pull/5589` [#​5720]: `https://github.com/ReactTraining/react-router/pull/5720` [#​5508]: `https://github.com/ReactTraining/react-router/pull/5508` [#​5792]: `https://github.com/ReactTraining/react-router/pull/5792` [e6f9017]: remix-run/react-router@e6f9017 [#​5964]: `https://github.com/ReactTraining/react-router/pull/5964` [#​5722]: `https://github.com/ReactTraining/react-router/pull/5722` --- </details> --- This PR has been generated by [Renovate Bot](https://renovatebot.com). Co-authored-by: Renovate Bot <[email protected]>
* fix: remove aria-current from navLink when inactive * Add parens so order-of-operations is clear * Still allow ariaCurrent value to pass through * fix: convert used of aria-current to standard React aria-* pattern and add valid values
Partially closes #5507.
Refer to the following two
aria-current
pattern docs from Léonie Watson:https://tink.uk/using-the-aria-current-attribute/
http://design-patterns.tink.uk/aria-current/
Both indicates the
aria-current
ARIA state only being rendered on the current element, instead of setting it tofalse
.I have changed the
NavLink
component to not render this attribute unless it should be set totrue
.This change fixes one of the issues from #5507 , namely that only the active link is then read out by NVDA to be active, instead of all the NavLinks.