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,
|
onOut: onPressOut,
|
||||||
} = useInteractionState()
|
} = 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({
|
return children({
|
||||||
isNative: true,
|
isNative: true,
|
||||||
control: context.control,
|
control: context.control,
|
||||||
state: {
|
state: {
|
||||||
|
activated,
|
||||||
hovered: false,
|
hovered: false,
|
||||||
focused,
|
focused,
|
||||||
pressed,
|
pressed,
|
||||||
|
|||||||
@@ -119,6 +119,11 @@ export function Trigger({children, label, role = 'button'}: TriggerProps) {
|
|||||||
} = useInteractionState()
|
} = useInteractionState()
|
||||||
const {state: focused, onIn: onFocus, onOut: onBlur} = 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 (
|
return (
|
||||||
<DropdownMenu.Trigger asChild>
|
<DropdownMenu.Trigger asChild>
|
||||||
<RadixTriggerPassThrough>
|
<RadixTriggerPassThrough>
|
||||||
@@ -127,6 +132,7 @@ export function Trigger({children, label, role = 'button'}: TriggerProps) {
|
|||||||
isNative: false,
|
isNative: false,
|
||||||
control,
|
control,
|
||||||
state: {
|
state: {
|
||||||
|
activated,
|
||||||
hovered,
|
hovered,
|
||||||
focused,
|
focused,
|
||||||
pressed: false,
|
pressed: false,
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ export type TriggerChildProps =
|
|||||||
hovered: false
|
hovered: false
|
||||||
focused: boolean
|
focused: boolean
|
||||||
pressed: boolean
|
pressed: boolean
|
||||||
|
activated: boolean
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* We don't necessarily know what these will be spread on to, so we
|
* 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
|
* Native only, `false` on web
|
||||||
*/
|
*/
|
||||||
pressed: false
|
pressed: false
|
||||||
|
activated: boolean
|
||||||
}
|
}
|
||||||
props: RadixPassThroughTriggerProps & {
|
props: RadixPassThroughTriggerProps & {
|
||||||
onPress: () => void
|
onPress: () => void
|
||||||
|
|||||||
@@ -104,13 +104,10 @@ function ProfileCard() {
|
|||||||
{!isLoading && profile ? (
|
{!isLoading && profile ? (
|
||||||
<Menu.Root>
|
<Menu.Root>
|
||||||
<Menu.Trigger label={_(msg`Switch accounts`)}>
|
<Menu.Trigger label={_(msg`Switch accounts`)}>
|
||||||
{({props, state, control}) => {
|
{({props, state}) => {
|
||||||
const active =
|
const active =
|
||||||
gtTablet && // desktop only
|
gtTablet && // desktop only
|
||||||
(state.hovered ||
|
state.activated
|
||||||
state.focused ||
|
|
||||||
state.pressed ||
|
|
||||||
control.isOpen)
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
label={props.accessibilityLabel}
|
label={props.accessibilityLabel}
|
||||||
|
|||||||
Reference in New Issue
Block a user