-
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(popover): consistent restore focus
- Loading branch information
1 parent
4ecff96
commit a931be7
Showing
4 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@zag-js/popover": patch | ||
--- | ||
|
||
Fix issue where popover does not restore focus when open state is changed programmatically |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Fragment, useId, useState } from "react" | ||
import * as popover from "@zag-js/popover" | ||
import { useMachine, normalizeProps, Portal } from "@zag-js/react" | ||
|
||
export default function Page() { | ||
const [open, setOpen] = useState(false) | ||
|
||
const initialContext = { | ||
id: useId(), | ||
open: false, | ||
"open.controlled": true, | ||
} | ||
|
||
const [state, send] = useMachine(popover.machine(initialContext), { | ||
context: { | ||
...initialContext, | ||
onOpenChange: (details) => setOpen(details.open), | ||
open: open, | ||
}, | ||
}) | ||
|
||
const api = popover.connect(state, send, normalizeProps) | ||
|
||
const Wrapper = api.portalled ? Portal : Fragment | ||
|
||
return ( | ||
<main> | ||
<button {...api.getTriggerProps()}>Click me</button> | ||
<Wrapper> | ||
<div {...api.getPositionerProps()}> | ||
<div {...api.getContentProps()}> | ||
<div {...api.getTitleProps()}>Presenters</div> | ||
<div {...api.getDescriptionProps()}>Description</div> | ||
<button onClick={() => setOpen(false)}>Action Button</button> | ||
</div> | ||
</div> | ||
</Wrapper> | ||
</main> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters