Skip to content

Commit b98d2da

Browse files
committed
feat(ActionList): prevent hover state if another item is active/focused
1 parent 5ebbc6c commit b98d2da

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/ActionList/Item.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ const StyledItem = styled.div<
181181
182182
@media (hover: hover) and (pointer: fine) {
183183
:hover {
184-
background: ${({hoverBackground}) => hoverBackground};
184+
// allow override in case another item in the list is active/focused
185+
background: var(--item-hover-bg-override, ${({hoverBackground}) => hoverBackground});
185186
cursor: ${({variant, item}) => getItemVariant(variant, item?.disabled).hoverCursor};
186187
}
187188
}
@@ -207,7 +208,11 @@ const StyledItem = styled.div<
207208
&:hover ${StyledItemContent}::before,
208209
// - below Hovered
209210
// '*' instead of '&' because '&' maps to separate class names depending on 'variant'
210-
:hover + * ${StyledItemContent}::before,
211+
:hover + * ${StyledItemContent}::before {
212+
// allow override in case another item in the list is active/focused
213+
border-color: var(--item-hover-divider-border-color-override, transparent) !important;
214+
}
215+
211216
// - above Focused
212217
&:focus ${StyledItemContent}::before,
213218
// - below Focused

src/ActionList/List.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Divider} from './Divider'
66
import styled from 'styled-components'
77
import {get} from '../constants'
88
import {SystemCssProperties} from '@styled-system/css'
9+
import {hasActiveDescendantAttribute} from '../behaviors/focusZone'
910

1011
export type ItemInput = ItemProps | (Partial<ItemProps> & {renderItem: typeof Item})
1112

@@ -102,6 +103,11 @@ const StyledList = styled.div`
102103
* hardcoded '20px'
103104
*/
104105
line-height: 20px;
106+
107+
&[${hasActiveDescendantAttribute}], &:focus-within {
108+
--item-hover-bg-override: none;
109+
--item-hover-divider-border-color-override: ${get('colors.selectMenu.borderSecondary')};
110+
}
105111
`
106112

107113
/**

src/behaviors/focusZone.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ function shouldIgnoreFocusHandling(keyboardEvent: KeyboardEvent, activeElement:
315315
export const isActiveDescendantAttribute = 'data-is-active-descendant'
316316
export const activeDescendantActivatedDirectly = 'activated-directly'
317317
export const activeDescendantActivatedIndirectly = 'activated-indirectly'
318+
export const hasActiveDescendantAttribute = 'data-has-active-descendant'
318319

319320
/**
320321
* Sets up the arrow key focus behavior for all focusable elements in the given `container`.
@@ -381,6 +382,7 @@ export function focusZone(container: HTMLElement, settings?: FocusZoneSettings):
381382
}
382383

383384
activeDescendantControl.setAttribute('aria-activedescendant', to.id)
385+
container.setAttribute(hasActiveDescendantAttribute, to.id)
384386
to.setAttribute(
385387
isActiveDescendantAttribute,
386388
directlyActivated ? activeDescendantActivatedDirectly : activeDescendantActivatedIndirectly
@@ -394,6 +396,7 @@ export function focusZone(container: HTMLElement, settings?: FocusZoneSettings):
394396
}
395397

396398
activeDescendantControl?.removeAttribute('aria-activedescendant')
399+
container.removeAttribute(hasActiveDescendantAttribute)
397400
previouslyActiveElement?.removeAttribute(isActiveDescendantAttribute)
398401
activeDescendantCallback?.(undefined, previouslyActiveElement, false)
399402
}

0 commit comments

Comments
 (0)