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

feat(header-menu-item): add isActive prop to apply styles to selected item #5504

Merged
merged 25 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
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 Mar 2, 2020
5fbfece
Merge branch 'master' into fix-3674-ui-shell
abbeyhrt Mar 2, 2020
d176d99
fix(ui-shell): update snapshots
abbeyhrt Mar 2, 2020
9785361
feat(ui-shell): adjust selected style and change isActive to isCurren…
abbeyhrt Mar 4, 2020
76abe89
Merge branch 'master' into fix-3674-ui-shell
abbeyhrt Mar 4, 2020
01fc4da
chore(ui-shell): run build for sass.md changes
abbeyhrt Mar 4, 2020
8579af9
Merge branch 'fix-3674-ui-shell' of https://github.com/abbeyhrt/my-ca…
abbeyhrt Mar 4, 2020
3f27035
fix(ui-shell): update snapshots
abbeyhrt Mar 4, 2020
2010d83
Merge branch 'master' into fix-3674-ui-shell
tw15egan Mar 5, 2020
adc9f1b
Merge branch 'master' into fix-3674-ui-shell
tw15egan Mar 5, 2020
2f9f444
Merge branch 'master' into fix-3674-ui-shell
tw15egan Mar 9, 2020
a345506
fix(header-menu-item): adjust border styles
abbeyhrt Mar 9, 2020
497f234
Merge branch 'fix-3674-ui-shell' of https://github.com/abbeyhrt/my-ca…
abbeyhrt Mar 9, 2020
99ad9a6
Merge branch 'master' into fix-3674-ui-shell
tw15egan Mar 10, 2020
28714b7
Merge branch 'master' into fix-3674-ui-shell
tw15egan Mar 11, 2020
abc416a
Merge branch 'fix-3674-ui-shell' of https://github.com/abbeyhrt/my-ca…
abbeyhrt Mar 12, 2020
77bc6da
Merge branch 'master' into fix-3674-ui-shell
abbeyhrt Mar 12, 2020
bd2700c
Merge branch 'master' into fix-3674-ui-shell
tw15egan Mar 13, 2020
41581d0
fix(ui-shell): adjust styles so focus is rectangular
abbeyhrt Mar 23, 2020
ee640a1
Merge branch 'fix-3674-ui-shell' of https://github.com/abbeyhrt/my-ca…
abbeyhrt Mar 23, 2020
971ab4f
Update packages/components/src/components/ui-shell/_header.scss
abbeyhrt Mar 23, 2020
9aea645
Merge branch 'master' into fix-3674-ui-shell
abbeyhrt Mar 23, 2020
86e81f6
Merge branch 'master' into fix-3674-ui-shell
abbeyhrt Mar 24, 2020
6b49d61
Merge branch 'master' into fix-3674-ui-shell
tw15egan Apr 1, 2020
b8dc12e
Merge branch 'master' into fix-3674-ui-shell
joshblack Apr 7, 2020
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
20 changes: 18 additions & 2 deletions packages/components/docs/sass.md
Original file line number Diff line number Diff line change
Expand Up @@ -7054,6 +7054,7 @@ $inverse-support-04: if(
- [carbon--theme [mixin]](#carbon--theme-mixin)
- [inline-notifications [mixin]](#inline-notifications-mixin)
- [toast-notifications [mixin]](#toast-notifications-mixin)
- [carbon-header [mixin]](#carbon-header-mixin)

### ✅overlay-01 [variable]

Expand Down Expand Up @@ -24459,7 +24460,6 @@ UI shell header
right: 0;
height: mini-units(6);
background-color: $shell-header-bg-01;
border-bottom: 1px solid $shell-header-border-01;
z-index: z('header');
}

Expand Down Expand Up @@ -24651,6 +24651,21 @@ UI shell header
fill: $shell-header-icon-01;
}

// Styles for selected state

a.#{$prefix}--header__menu-item[aria-current='page'],
a.#{$prefix}--header__menu-item.#{$prefix}--header__menu-item--current {
color: $shell-header-text-01;
border-left: 0;
border-right: 0;
border-bottom: 3px solid $inverse-support-04;
}

a.#{$prefix}--header__menu-item[aria-current='page']:focus,
a.#{$prefix}--header__menu-item.#{$prefix}--header__menu-item--current:focus {
border: 2px solid $shell-header-focus;
}

.#{$prefix}--header__submenu {
position: relative;
}
Expand Down Expand Up @@ -24772,15 +24787,16 @@ UI shell header
- [mini-units [function]](#mini-units-function)
- [prefix [variable]](#prefix-variable)
- [shell-header-bg-01 [variable]](#shell-header-bg-01-variable)
- [shell-header-border-01 [variable]](#shell-header-border-01-variable)
- [shell-header-bg-04 [variable]](#shell-header-bg-04-variable)
- [shell-header-border-01 [variable]](#shell-header-border-01-variable)
- [shell-header-focus [variable]](#shell-header-focus-variable)
- [shell-header-bg-03 [variable]](#shell-header-bg-03-variable)
- [shell-header-icon-02 [variable]](#shell-header-icon-02-variable)
- [shell-header-icon-01 [variable]](#shell-header-icon-01-variable)
- [shell-header-bg-02 [variable]](#shell-header-bg-02-variable)
- [shell-header-text-01 [variable]](#shell-header-text-01-variable)
- [shell-header-text-02 [variable]](#shell-header-text-02-variable)
- [inverse-support-04 [variable]](#inverse-support-04-variable)
- [shell-header-bg-06 [variable]](#shell-header-bg-06-variable)
- [shell-header-icon-03 [variable]](#shell-header-icon-03-variable)

Expand Down
14 changes: 13 additions & 1 deletion packages/components/src/components/ui-shell/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
right: 0;
height: mini-units(6);
background-color: $shell-header-bg-01;
border-bottom: 1px solid $shell-header-border-01;
z-index: z('header');
}

Expand Down Expand Up @@ -219,6 +218,19 @@
fill: $shell-header-icon-01;
}

// Styles for selected state

a.#{$prefix}--header__menu-item[aria-current='page'],
a.#{$prefix}--header__menu-item.#{$prefix}--header__menu-item--current {
color: $shell-header-text-01;
border-bottom: 2px solid $inverse-support-04;
}

a.#{$prefix}--header__menu-item[aria-current='page']:focus,
a.#{$prefix}--header__menu-item.#{$prefix}--header__menu-item--current:focus {
border: 2px solid $shell-header-focus;
}

.#{$prefix}--header__submenu {
position: relative;
}
Expand Down
3 changes: 3 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6238,6 +6238,9 @@ Map {
"element": Object {
"type": "elementType",
},
"isCurrentPage": Object {
"type": "bool",
},
"isSideNavExpanded": Object {
"type": "bool",
},
Expand Down
26 changes: 24 additions & 2 deletions packages/react/src/components/UIShell/HeaderMenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

aria-current="page" is more stable and not likely to change

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

Copy link
Contributor

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 with page seems like a fairly consistent attribute for communicating present navigation to screen readers.

Copy link
Contributor

@asudoh asudoh Mar 17, 2020

Choose a reason for hiding this comment

The 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
isCurrentPage && ariaCurrent !== 'page',
isCurrentPage,

});

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>
Expand Down Expand Up @@ -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;
4 changes: 3 additions & 1 deletion packages/react/src/components/UIShell/UIShell-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ storiesOf('UI Shell', module)
[Platform]
</HeaderName>
<HeaderNavigation aria-label="IBM [Platform]">
<HeaderMenuItem href="#">Link 1</HeaderMenuItem>
<HeaderMenuItem isCurrentPage="true" href="#">
Link 1
</HeaderMenuItem>
<HeaderMenuItem href="#">Link 2</HeaderMenuItem>
<HeaderMenuItem href="#">Link 3</HeaderMenuItem>
<HeaderMenu aria-label="Link 4" menuLinkName="Link 4">
Expand Down