Skip to content

Commit

Permalink
fix(tags): delete key behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Oct 8, 2024
1 parent 8de6e8f commit 309ec9e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-otters-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zag-js/tags-input": patch
---

Fix issue where tags input doesn't navigate tags after removing with the delete key
1 change: 1 addition & 0 deletions .xstate/tags-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ const fetchMachine = createMachine({
actions: ["deleteHighlightedTag", "highlightPrevTag"]
}],
DELETE: {
target: "focused:input",
actions: ["deleteHighlightedTag", "highlightTagAtIndex"]
},
PASTE: [{
Expand Down
12 changes: 12 additions & 0 deletions e2e/tags-input.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ test.describe("tags-input", () => {
await I.dontSeeTag("Vue")
})

test("delete tag with delete key, show allow keyboard navigation", async () => {
await I.focusInput()
await I.pressKey("ArrowLeft")
await I.pressKey("Delete")

await I.seeInputIsFocused()
await I.dontSeeTag("Vue")

await I.pressKey("ArrowLeft")
await I.seeTagIsHighlighted("React")
})

test("delete tag with pointer, show allow keyboard navigation", async () => {
await I.clickTagClose("Vue")

Expand Down
1 change: 1 addition & 0 deletions packages/machines/tags-input/src/tags-input.machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export function machine(userContext: UserDefinedContext) {
},
],
DELETE: {
target: "focused:input",
actions: ["deleteHighlightedTag", "highlightTagAtIndex"],
},
PASTE: [
Expand Down

0 comments on commit 309ec9e

Please sign in to comment.