Skip to content

Commit

Permalink
fix(@clayui/vertical-nav): Add aria-controls on vertical navbar itens…
Browse files Browse the repository at this point in the history
… and change role to menuitem
  • Loading branch information
ilzamcmed committed Jan 16, 2024
1 parent 7a967d8 commit 7e2a35b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/clay-core/src/vertical-nav/Item.tsx
Expand Up @@ -4,7 +4,7 @@
*/

import {useProvider} from '@clayui/provider';
import {Keys, setElementFullHeight} from '@clayui/shared';
import {Keys, setElementFullHeight, useId} from '@clayui/shared';
import React, {useContext, useMemo, useRef, useState} from 'react';
import {CSSTransition} from 'react-transition-group';

Expand Down Expand Up @@ -128,13 +128,15 @@ export function Item<T extends object>({

const active = depreactedActive ?? activeKey === keyValue;

const ariaControlsId = useId();

return (
<Nav.Item role="none" {...otherProps}>
<Nav.Link
active={active}
aria-controls={items ? ariaControlsId : undefined}
aria-current={active ? ariaCurrent ?? undefined : undefined}
aria-expanded={items ? isExpanded : undefined}
aria-haspopup={items ? true : undefined}
collapsed={!isExpanded}
href={href}
onClick={(event) => {
Expand Down Expand Up @@ -188,7 +190,7 @@ export function Item<T extends object>({
}
}}
ref={itemRef}
role={items ? 'button' : 'menuitem'}
role="menuitem"
showIcon={!!items}
spritemap={spritemap}
tabIndex={
Expand Down Expand Up @@ -229,7 +231,7 @@ export function Item<T extends object>({
timeout={prefersReducedMotion ? 0 : 250}
unmountOnExit
>
<Nav ref={menusRef} role="menu" stacked>
<Nav id={ariaControlsId} ref={menusRef} role="menu" stacked>
<ParentContext.Provider value={itemRef}>
<Collection<T> items={items} parentKey={keyValue}>
{childrenRoot.current}
Expand Down

0 comments on commit 7e2a35b

Please sign in to comment.