Skip to content

Commit

Permalink
fix: select focus return
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Sep 5, 2024
1 parent ed6a8a2 commit 664fd91
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-icons-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zag-js/select": patch
---

Fix regression where select doesn't restore focus to trigger on keyboard selection
2 changes: 1 addition & 1 deletion .xstate/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ const fetchMachine = createMachine({
}, {
cond: "closeOnSelect",
target: "focused",
actions: ["selectHighlightedItem", "invokeOnClose", "clearHighlightedItem"]
actions: ["selectHighlightedItem", "invokeOnClose", "focusTriggerEl", "clearHighlightedItem"]
}, {
actions: ["selectHighlightedItem"]
}],
Expand Down
3 changes: 3 additions & 0 deletions e2e/select.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ test.describe("keyboard / select", () => {
await I.pressKey("Enter")
await I.seeItemIsChecked("Andorra")
await I.seeTriggerHasText("Andorra")
await I.seeTriggerIsFocused()
})

test("should select on space", async () => {
Expand All @@ -121,13 +122,15 @@ test.describe("keyboard / select", () => {
await I.pressKey(" ")
await I.seeItemIsChecked("Andorra")
await I.seeTriggerHasText("Andorra")
await I.seeTriggerIsFocused()
})

test("should close on select", async () => {
await I.clickTrigger()
await I.pressKey("ArrowDown")
await I.pressKey("Enter")
await I.dontSeeDropdown()
await I.seeTriggerIsFocused()
})

test("should not close on closeOnSelect = false", async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/machines/select/src/select.machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export function machine<T extends CollectionItem>(userContext: UserDefinedContex
{
guard: "closeOnSelect",
target: "focused",
actions: ["selectHighlightedItem", "invokeOnClose", "clearHighlightedItem"],
actions: ["selectHighlightedItem", "invokeOnClose", "focusTriggerEl", "clearHighlightedItem"],
},
{
actions: ["selectHighlightedItem"],
Expand Down

0 comments on commit 664fd91

Please sign in to comment.