Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 19 additions & 3 deletions src/components/dropdown-menu/DropdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const DropdownMenu = ({
variant = "default",
}: PropsWithChildren<DropdownMenuProps>) => {
const id = useId();
const menuId = `${id}-menu`;
const triggerRef = useRef(null);
const menuClassName = `c__dropdown-menu${
variant === "tiny" ? " c__dropdown-menu--tiny" : ""
Expand All @@ -77,6 +78,12 @@ export const DropdownMenu = ({
}

const itemKey = option.id || option.label;
const isSelectable =
option.value !== undefined || option.isChecked !== undefined;
const isSelected = Boolean(
option.isChecked ||
(option.value && selectedValues.includes(option.value))
);

if (hasChildren(option)) {
return (
Expand All @@ -86,6 +93,7 @@ export const DropdownMenu = ({
"c__dropdown-menu-item--danger": option.variant === "danger",
})}
aria-label={option.label}
aria-checked={isSelectable ? isSelected : undefined}
isDisabled={option.isDisabled}
data-testid={option.testId}
>
Expand All @@ -110,6 +118,7 @@ export const DropdownMenu = ({
"c__dropdown-menu-item--danger": option.variant === "danger",
})}
aria-label={option.label}
aria-checked={isSelectable ? isSelected : undefined}
onAction={() => {
if (option.value) {
onSelectValue?.(option.value);
Expand All @@ -123,8 +132,7 @@ export const DropdownMenu = ({
data-testid={option.testId}
>
<MenuItemContent option={option} />
{(option.isChecked ||
(option.value && selectedValues.includes(option.value))) && (
{isSelected && (
<span className="material-icons checked">check</span>
)}
</MenuItem>
Expand All @@ -140,6 +148,9 @@ export const DropdownMenu = ({
className="c__dropdown-menu-trigger"
ref={triggerRef}
id={id}
aria-haspopup="menu"
aria-expanded={isOpen}
aria-controls={isOpen ? menuId : undefined}
onClick={(e) => {
e.stopPropagation();
e.preventDefault();
Expand All @@ -159,7 +170,12 @@ export const DropdownMenu = ({
shouldCloseOnInteractOutside={shouldCloseOnInteractOutside}
onOpenChange={onOpenChangeHandler}
>
<Menu className={menuClassName} aria-labelledby={id} autoFocus="first">
<Menu
id={menuId}
className={menuClassName}
aria-labelledby={id}
autoFocus="first"
>
{topMessage && (
<Header
className="c__dropdown-menu-item-top-message"
Expand Down
5 changes: 5 additions & 0 deletions src/components/dropdown-menu/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@
);
}

&[data-focused] {
box-shadow: inset 0 0 0 2px
var(--c--contextuals--border--semantic--active--primary, #000091);
}

&[data-disabled] {
color: var(--c--contextuals--content--semantic--disabled--primary);
cursor: not-allowed;
Expand Down