Abstract lag in control.isOpen state
This commit is contained in:
committed by
Samuel Newman
parent
730234ec76
commit
62c3b9f9c9
@@ -56,10 +56,16 @@ export function Trigger({children, label, role = 'button'}: TriggerProps) {
|
||||
onOut: onPressOut,
|
||||
} = useInteractionState()
|
||||
|
||||
const prevControlIsOpen = React.useRef(context.control.isOpen)
|
||||
const open = prevControlIsOpen.current || context.control.isOpen
|
||||
const activated = Boolean(pressed || focused || open)
|
||||
prevControlIsOpen.current = context.control.isOpen
|
||||
|
||||
return children({
|
||||
isNative: true,
|
||||
control: context.control,
|
||||
state: {
|
||||
activated,
|
||||
hovered: false,
|
||||
focused,
|
||||
pressed,
|
||||
|
||||
@@ -119,6 +119,11 @@ export function Trigger({children, label, role = 'button'}: TriggerProps) {
|
||||
} = useInteractionState()
|
||||
const {state: focused, onIn: onFocus, onOut: onBlur} = useInteractionState()
|
||||
|
||||
const prevControlIsOpen = React.useRef(control.isOpen)
|
||||
const open = prevControlIsOpen.current || control.isOpen
|
||||
const activated = Boolean(hovered || focused || open)
|
||||
prevControlIsOpen.current = control.isOpen
|
||||
|
||||
return (
|
||||
<DropdownMenu.Trigger asChild>
|
||||
<RadixTriggerPassThrough>
|
||||
@@ -127,6 +132,7 @@ export function Trigger({children, label, role = 'button'}: TriggerProps) {
|
||||
isNative: false,
|
||||
control,
|
||||
state: {
|
||||
activated,
|
||||
hovered,
|
||||
focused,
|
||||
pressed: false,
|
||||
|
||||
@@ -50,6 +50,7 @@ export type TriggerChildProps =
|
||||
hovered: false
|
||||
focused: boolean
|
||||
pressed: boolean
|
||||
activated: boolean
|
||||
}
|
||||
/**
|
||||
* We don't necessarily know what these will be spread on to, so we
|
||||
@@ -78,6 +79,7 @@ export type TriggerChildProps =
|
||||
* Native only, `false` on web
|
||||
*/
|
||||
pressed: false
|
||||
activated: boolean
|
||||
}
|
||||
props: RadixPassThroughTriggerProps & {
|
||||
onPress: () => void
|
||||
|
||||
@@ -104,13 +104,10 @@ function ProfileCard() {
|
||||
{!isLoading && profile ? (
|
||||
<Menu.Root>
|
||||
<Menu.Trigger label={_(msg`Switch accounts`)}>
|
||||
{({props, state, control}) => {
|
||||
{({props, state}) => {
|
||||
const active =
|
||||
gtTablet && // desktop only
|
||||
(state.hovered ||
|
||||
state.focused ||
|
||||
state.pressed ||
|
||||
control.isOpen)
|
||||
state.activated
|
||||
return (
|
||||
<Button
|
||||
label={props.accessibilityLabel}
|
||||
|
||||
Reference in New Issue
Block a user