@@ -8,7 +8,11 @@ import styled from 'styled-components'
88import { StyledHeader } from './Header'
99import { StyledDivider } from './Divider'
1010import { useColorSchemeVar , useTheme } from '../ThemeProvider'
11- import { uniqueId } from '../utils/uniqueId'
11+ import {
12+ activeDescendantActivatedDirectly ,
13+ activeDescendantActivatedIndirectly ,
14+ isActiveDescendantAttribute
15+ } from '../behaviors/focusZone'
1216
1317/**
1418 * These colors are not yet in our default theme. Need to remove this once they are added.
@@ -121,8 +125,6 @@ export interface ItemProps extends Omit<React.ComponentPropsWithoutRef<'div'>, '
121125 id ?: number | string
122126}
123127
124- export const itemActiveDescendantClass = `${ uniqueId ( ) } active-descendant`
125-
126128const getItemVariant = ( variant = 'default' , disabled ?: boolean ) => {
127129 if ( disabled ) {
128130 return {
@@ -176,10 +178,13 @@ const StyledItem = styled.div<
176178 display: flex;
177179 border-radius: ${ get ( 'radii.2' ) } ;
178180 color: ${ ( { variant, item} ) => getItemVariant ( variant , item ?. disabled ) . color } ;
181+ // 2 frames on a 60hz monitor
182+ transition: background 33.333ms linear;
179183
180184 @media (hover: hover) and (pointer: fine) {
181185 :hover {
182- background: ${ ( { hoverBackground} ) => hoverBackground } ;
186+ // allow override in case another item in the list is active/focused
187+ background: var(--item-hover-bg-override, ${ ( { hoverBackground} ) => hoverBackground } );
183188 cursor: ${ ( { variant, item} ) => getItemVariant ( variant , item ?. disabled ) . hoverCursor } ;
184189 }
185190 }
@@ -205,27 +210,41 @@ const StyledItem = styled.div<
205210 &:hover ${ StyledItemContent } ::before,
206211 // - below Hovered
207212 // '*' instead of '&' because '&' maps to separate class names depending on 'variant'
208- :hover + * ${ StyledItemContent } ::before,
213+ :hover + * ${ StyledItemContent } ::before {
214+ // allow override in case another item in the list is active/focused
215+ border-color: var(--item-hover-divider-border-color-override, transparent) !important;
216+ }
217+
209218 // - above Focused
210219 &:focus ${ StyledItemContent } ::before,
211220 // - below Focused
212221 // '*' instead of '&' because '&' maps to separate class names depending on 'variant'
213222 :focus + * ${ StyledItemContent } ::before,
214223 // - above Active Descendent
215- &. ${ itemActiveDescendantClass } ${ StyledItemContent } ::before,
224+ &[ ${ isActiveDescendantAttribute } ] ${ StyledItemContent } ::before,
216225 // - below Active Descendent
217- . ${ itemActiveDescendantClass } + & ${ StyledItemContent } ::before {
226+ [ ${ isActiveDescendantAttribute } ] + & ${ StyledItemContent } ::before {
218227 // '!important' because all the ':not's above give higher specificity
219228 border-color: transparent !important;
220229 }
221230
222- // Focused OR Active Descendant
223- &:focus,
224- &.${ itemActiveDescendantClass } {
231+ // Active Descendant
232+ &[${ isActiveDescendantAttribute } ='${ activeDescendantActivatedDirectly } '] {
233+ background: ${ ( { focusBackground} ) => focusBackground } ;
234+ }
235+ &[${ isActiveDescendantAttribute } ='${ activeDescendantActivatedIndirectly } '] {
236+ background: ${ ( { hoverBackground} ) => hoverBackground } ;
237+ }
238+
239+ &:focus {
225240 background: ${ ( { focusBackground} ) => focusBackground } ;
226241 outline: none;
227242 }
228243
244+ &:active {
245+ background: ${ ( { focusBackground} ) => focusBackground } ;
246+ }
247+
229248 ${ sx }
230249`
231250
0 commit comments