Skip to content

Commit

Permalink
fix focus ring color on menu and select component
Browse files Browse the repository at this point in the history
  • Loading branch information
lerte committed Nov 9, 2024
1 parent 755f1fa commit 2b47e19
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
27 changes: 23 additions & 4 deletions packages/actify/src/components/ListBox/Option.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,46 @@
import { AriaOptionProps, useOption } from 'react-aria'
import {
AriaFocusRingProps,
AriaOptionProps,
mergeProps,
useFocusRing,
useOption
} from 'react-aria'
import { ListState, Node } from 'react-stately'

import { FocusRing } from '../FocusRing'
import React from 'react'
import { Ripple } from './../Ripple'
import clsx from 'clsx'
import styles from './option.module.css'

interface OptionProps<T> extends AriaOptionProps {
interface OptionProps<T> extends AriaOptionProps, AriaFocusRingProps {
item: Node<T>
state: ListState<T>
}

const Option = <T extends object>({ item, state }: OptionProps<T>) => {
const Option = <T extends object>({
item,
state,
...props
}: OptionProps<T>) => {
const ref = React.useRef(null)
const { focusProps, isFocusVisible } = useFocusRing(props)
const { optionProps, isSelected } = useOption({ key: item.key }, state, ref)

return (
<li
ref={ref}
{...optionProps}
{...mergeProps(focusProps, optionProps)}
className={clsx(styles['item'], isSelected && styles['selected'])}
>
{item.rendered}
{isFocusVisible && (
<FocusRing
style={{
color: 'rgb(var(--md-sys-color-primary))'
}}
/>
)}
<Ripple />
</li>
)
Expand Down
4 changes: 2 additions & 2 deletions packages/actify/src/components/ListBox/listbox.module.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
.items {
list-style: none;
margin: 0;
padding: 0;
display: block;
padding-left: 8px;
padding-block: 8px;
padding-right: 8px;
list-style-type: none;
margin: 0;
outline: none;
box-sizing: border-box;
background-color: var(
Expand Down
3 changes: 3 additions & 0 deletions packages/actify/src/components/ListBox/option.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
padding-inline-start: var(--md-menu-item-leading-space, 16px);
padding-inline-end: var(--md-menu-item-trailing-space, 16px);
}
.item:focus-visible {
outline: none;
}
.item.selected {
background-color: var(
--md-menu-item-selected-container-color,
Expand Down
8 changes: 7 additions & 1 deletion packages/actify/src/components/Menus/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ export function MenuItem<T>({
{...mergeProps(menuItemProps, focusProps)}
>
<Item container={<Container />}>{item.rendered}</Item>
{isFocusVisible && <FocusRing />}
{isFocusVisible && (
<FocusRing
style={{
color: 'rgb(var(--md-sys-color-primary))'
}}
/>
)}
</li>
)
}
9 changes: 4 additions & 5 deletions packages/actify/src/components/Menus/menu.module.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
.menu {
border-radius: var(
--md-menu-container-shape,
var(--md-sys-shape-corner-extra-small, 4px)
);
display: none;
inset: auto;
border: none;
Expand Down Expand Up @@ -82,7 +78,10 @@
position: relative; /* for focus ring */
list-style: none;
background-color: var(--md-menu-item-container-color, transparent);
border-radius: inherit;
border-radius: var(
--md-menu-container-shape,
var(--md-sys-shape-corner-extra-small, 4px)
);
display: flex;
flex: 1;
max-width: inherit;
Expand Down

0 comments on commit 2b47e19

Please sign in to comment.