-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
feat(header-menu-item): add isActive prop to apply styles to selected item #5504
Merged
joshblack
merged 25 commits into
carbon-design-system:master
from
abbeyhrt:fix-3674-ui-shell
Apr 7, 2020
+73
−6
Merged
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
ca96865
feat(header-menuitem): add isActive prop to apply style to selected item
abbeyhrt 5fbfece
Merge branch 'master' into fix-3674-ui-shell
abbeyhrt d176d99
fix(ui-shell): update snapshots
abbeyhrt 9785361
feat(ui-shell): adjust selected style and change isActive to isCurren…
abbeyhrt 76abe89
Merge branch 'master' into fix-3674-ui-shell
abbeyhrt 01fc4da
chore(ui-shell): run build for sass.md changes
abbeyhrt 8579af9
Merge branch 'fix-3674-ui-shell' of https://github.com/abbeyhrt/my-ca…
abbeyhrt 3f27035
fix(ui-shell): update snapshots
abbeyhrt 2010d83
Merge branch 'master' into fix-3674-ui-shell
tw15egan adc9f1b
Merge branch 'master' into fix-3674-ui-shell
tw15egan 2f9f444
Merge branch 'master' into fix-3674-ui-shell
tw15egan a345506
fix(header-menu-item): adjust border styles
abbeyhrt 497f234
Merge branch 'fix-3674-ui-shell' of https://github.com/abbeyhrt/my-ca…
abbeyhrt 99ad9a6
Merge branch 'master' into fix-3674-ui-shell
tw15egan 28714b7
Merge branch 'master' into fix-3674-ui-shell
tw15egan abc416a
Merge branch 'fix-3674-ui-shell' of https://github.com/abbeyhrt/my-ca…
abbeyhrt 77bc6da
Merge branch 'master' into fix-3674-ui-shell
abbeyhrt bd2700c
Merge branch 'master' into fix-3674-ui-shell
tw15egan 41581d0
fix(ui-shell): adjust styles so focus is rectangular
abbeyhrt ee640a1
Merge branch 'fix-3674-ui-shell' of https://github.com/abbeyhrt/my-ca…
abbeyhrt 971ab4f
Update packages/components/src/components/ui-shell/_header.scss
abbeyhrt 9aea645
Merge branch 'master' into fix-3674-ui-shell
abbeyhrt 86e81f6
Merge branch 'master' into fix-3674-ui-shell
abbeyhrt 6b49d61
Merge branch 'master' into fix-3674-ui-shell
tw15egan b8dc12e
Merge branch 'master' into fix-3674-ui-shell
joshblack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,19 +8,36 @@ | |||||
import { settings } from 'carbon-components'; | ||||||
import PropTypes from 'prop-types'; | ||||||
import React from 'react'; | ||||||
import cx from 'classnames'; | ||||||
import Link, { LinkPropTypes } from './Link'; | ||||||
|
||||||
const { prefix } = settings; | ||||||
|
||||||
const HeaderMenuItem = React.forwardRef(function HeaderMenuItem( | ||||||
{ className, children, role, ...rest }, | ||||||
{ | ||||||
className, | ||||||
isCurrentPage, | ||||||
'aria-current': ariaCurrent, | ||||||
children, | ||||||
role, | ||||||
...rest | ||||||
}, | ||||||
ref | ||||||
) { | ||||||
const linkClassName = cx({ | ||||||
[`${prefix}--header__menu-item`]: true, | ||||||
// We set the current class only if `isCurrentPage` is passed in and we do | ||||||
// not have an `aria-current="page"` set for the breadcrumb item | ||||||
[`${prefix}--header__menu-item--current`]: | ||||||
isCurrentPage && ariaCurrent !== 'page', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just in case if this clarifies what the code should be:
Suggested change
|
||||||
}); | ||||||
|
||||||
return ( | ||||||
<li className={className} role={role}> | ||||||
<Link | ||||||
{...rest} | ||||||
className={`${prefix}--header__menu-item`} | ||||||
aria-current={ariaCurrent} | ||||||
className={linkClassName} | ||||||
ref={ref} | ||||||
tabIndex={0}> | ||||||
<span className={`${prefix}--text-truncate--end`}>{children}</span> | ||||||
|
@@ -52,6 +69,11 @@ HeaderMenuItem.propTypes = { | |||||
* <ul> semantics for menus. | ||||||
*/ | ||||||
role: PropTypes.string, | ||||||
|
||||||
/** | ||||||
* Applies selected styles to the item if a user sets this to true and aria-current !== 'page'. | ||||||
*/ | ||||||
isCurrentPage: PropTypes.bool, | ||||||
}; | ||||||
|
||||||
export default HeaderMenuItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Usage of ARIA attribute content for styling has caused breaking changes during our a11y fix effort. So wondering if just
isCurrentPage
is enough.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 don't think we'll run into any problems since it's being implemented in both ways. It definitely is risky to style using ARIA roles since we might change those based on new info but
aria-current="page"
is more stable and not likely to change. I also think it's nice to support both use cases for the ways that people might try to implement current page styling.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.
Probably it may change (esp. in post-IE era) because of newer spec in this area is on the horizon https://wicg.github.io/aom/explainer.html
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.
It seems like it'd be good to go for now, given the class fallback. If there is a specific line or section from the spec that you think is relevant and should be included in the PR that'd be great to highlight 👍
aria-current
withpage
seems like a fairly consistent attribute for communicating present navigation to screen readers.