From efe092898c391c161a46c7b78eb5482855fa0485 Mon Sep 17 00:00:00 2001 From: MadanKumarGovindaswamy Date: Thu, 16 May 2024 16:04:31 +0530 Subject: [PATCH] update: A11y changes --- .../example/DrillInExample.jsx | 1 + .../src/NavigationSideMenu.jsx | 10 ++++- .../src/NavigationSideMenu.module.scss | 11 +++++ .../src/_MenuItem.jsx | 12 ++++- .../NavigationSideMenu.test.jsx.snap | 45 ++++++++++++++----- 5 files changed, 65 insertions(+), 14 deletions(-) diff --git a/packages/terra-framework-docs/src/terra-dev-site/doc/navigation-side-menu/example/DrillInExample.jsx b/packages/terra-framework-docs/src/terra-dev-site/doc/navigation-side-menu/example/DrillInExample.jsx index 0659bfefd4..f4616b98bd 100644 --- a/packages/terra-framework-docs/src/terra-dev-site/doc/navigation-side-menu/example/DrillInExample.jsx +++ b/packages/terra-framework-docs/src/terra-dev-site/doc/navigation-side-menu/example/DrillInExample.jsx @@ -56,6 +56,7 @@ class DrillInDefault extends React.Component { selectedChildKey={this.state.selectedChildKey} ariaLabel="Sub Menu List" variant={VARIANTS.DRILL_IN} + headerLevel={3} /> ); diff --git a/packages/terra-navigation-side-menu/src/NavigationSideMenu.jsx b/packages/terra-navigation-side-menu/src/NavigationSideMenu.jsx index 3e859078fe..885796000a 100644 --- a/packages/terra-navigation-side-menu/src/NavigationSideMenu.jsx +++ b/packages/terra-navigation-side-menu/src/NavigationSideMenu.jsx @@ -24,6 +24,10 @@ const propTypes = { * String that labels the navigation menu for screen readers. */ ariaLabel: PropTypes.string, + /** + * The heading level for the title of the menu. + */ + headerLevel: PropTypes.oneOf([1, 2, 3, 4, 5, 6]), /** * An array of configuration for each menu item. */ @@ -96,6 +100,7 @@ const propTypes = { const defaultProps = { menuItems: [], variant: VARIANTS.NAVIGATION_SIDE_MENU, + headerLevel: 3, }; const processMenuItems = (menuItems, variant) => { @@ -379,6 +384,7 @@ class NavigationSideMenu extends Component { selectedMenuKey, toolbar, variant, + headerLevel, ...customProps } = this.props; const currentItem = this.state.items[selectedMenuKey]; @@ -388,6 +394,8 @@ class NavigationSideMenu extends Component { theme.className, ]); + const HeaderElement = `h${headerLevel}`; + const parentKey = this.state.parents[selectedMenuKey]; if (parentKey) { this.onBack = this.handleBackClick; @@ -415,7 +423,7 @@ class NavigationSideMenu extends Component { data-navigation-side-menu > {(this.onBack) ? : null} -

{currentItem ? currentItem.text : null}

+ {currentItem ? currentItem.text : null} {toolbar} diff --git a/packages/terra-navigation-side-menu/src/NavigationSideMenu.module.scss b/packages/terra-navigation-side-menu/src/NavigationSideMenu.module.scss index dd4504a15a..e217d21ab2 100644 --- a/packages/terra-navigation-side-menu/src/NavigationSideMenu.module.scss +++ b/packages/terra-navigation-side-menu/src/NavigationSideMenu.module.scss @@ -84,4 +84,15 @@ width: 100%; word-wrap: break-word; /* For IE 10 and IE 11 */ } + + .drill-in-title { + color: var(--terra-navigation-side-menu-header-color); + font-weight: 700; + hyphens: auto; + margin: 5px; + overflow-wrap: break-word; /* Modern browsers */ + padding: 0.28571rem; + width: 100%; + word-wrap: break-word; /* For IE 10 and IE 11 */ + } } diff --git a/packages/terra-navigation-side-menu/src/_MenuItem.jsx b/packages/terra-navigation-side-menu/src/_MenuItem.jsx index b7e37ec299..c923276059 100644 --- a/packages/terra-navigation-side-menu/src/_MenuItem.jsx +++ b/packages/terra-navigation-side-menu/src/_MenuItem.jsx @@ -120,7 +120,7 @@ class MenuItem extends React.Component { } = this.props; const theme = this.context; - const itemIcon = hasChevron && !icon ? : (icon || ); + const itemIcon = hasChevron && !icon ? : (icon || ); const itemClassNames = classNames(cx( 'menu-item', @@ -137,6 +137,14 @@ class MenuItem extends React.Component { { 'is-disabled': isDisabled }, ); + const ariaAttributes = {}; + ariaAttributes['aria-haspopup'] = hasChevron; + ariaAttributes['aria-disabled'] = isDisabled; + + if (hasChevron) { + ariaAttributes['aria-expanded'] = !hasChevron; + } + return (
  • {variant === VARIANTS.DRILL_IN && itemIcon && {itemIcon}}
    diff --git a/packages/terra-navigation-side-menu/tests/jest/__snapshots__/NavigationSideMenu.test.jsx.snap b/packages/terra-navigation-side-menu/tests/jest/__snapshots__/NavigationSideMenu.test.jsx.snap index 75e0f9a2d4..d3755e9ac1 100644 --- a/packages/terra-navigation-side-menu/tests/jest/__snapshots__/NavigationSideMenu.test.jsx.snap +++ b/packages/terra-navigation-side-menu/tests/jest/__snapshots__/NavigationSideMenu.test.jsx.snap @@ -71,6 +71,7 @@ exports[`Layout correctly applies the theme context className 1`] = ` selectedMenuKey="menu" > -

    Test Menu -

    +
  • -

    Test Menu -

    + -

    Test Menu -

    +
    + + Document + @@ -1602,11 +1613,13 @@ exports[`Layout should render a drill-in variant of NavigationSideMenu with sele className="icon" > + + Document + @@ -1704,11 +1719,13 @@ exports[`Layout should render a drill-in variant of NavigationSideMenu with sele className="icon" > + + Document + @@ -1806,11 +1825,13 @@ exports[`Layout should render a drill-in variant of NavigationSideMenu with sele className="icon" > + + Document +