Skip to content

Commit

Permalink
ensure focus event is triggered on click when element is focusable
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinMalfait committed Feb 4, 2021
1 parent 0350a88 commit 3610a48
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/@headlessui-react/src/test-utils/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ export async function click(
if (!cancelled) {
fireEvent.mouseDown(element, options)
}

// Ensure to trigger a `focus` event if the element is focusable
if ((element as HTMLElement)?.matches(focusableSelector)) fireEvent.focus(element, options)

fireEvent.pointerUp(element, options)
if (!cancelled) {
fireEvent.mouseUp(element, options)
Expand Down
4 changes: 4 additions & 0 deletions packages/@headlessui-vue/src/test-utils/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ export async function click(
if (!cancelled) {
fireEvent.mouseDown(element, options)
}

// Ensure to trigger a `focus` event if the element is focusable
if ((element as HTMLElement)?.matches(focusableSelector)) fireEvent.focus(element, options)

fireEvent.pointerUp(element, options)
if (!cancelled) {
fireEvent.mouseUp(element, options)
Expand Down

0 comments on commit 3610a48

Please sign in to comment.