Skip to content

Commit

Permalink
fix(Menu): return focus to trigger on close (#538)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced user interaction with menu components by ensuring the trigger
element gains focus after being clicked.

- **Chores**
- Updated dependencies for improved stability and performance, including
an upgrade to `@floating-ui/react`.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
aversini authored Apr 28, 2024
1 parent 1818315 commit 9d229b0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
12 changes: 4 additions & 8 deletions packages/ui-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"files": ["dist"],
"scripts": {
"build:check": "tsc",
"build:js": "vite build",
Expand All @@ -38,7 +36,7 @@
"test": "vitest run"
},
"peerDependencies": {
"@floating-ui/react": "0.26.12",
"@floating-ui/react": "0.26.13",
"fast-equals": "5.0.1",
"micro-memoize": "4.1.2",
"react": "^18.2.0",
Expand All @@ -48,15 +46,13 @@
"@versini/ui-styles": "workspace:../ui-styles"
},
"dependencies": {
"@floating-ui/react": "0.26.12",
"@floating-ui/react": "0.26.13",
"@tailwindcss/typography": "0.5.12",
"@versini/ui-hooks": "workspace:../ui-hooks",
"@versini/ui-icons": "workspace:../ui-icons",
"@versini/ui-private": "workspace:../ui-private",
"clsx": "2.1.1",
"tailwindcss": "3.4.3"
},
"sideEffects": [
"**/*.css"
]
"sideEffects": ["**/*.css"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ describe("Menu behaviors", () => {
expect(firstMenuItem).toHaveFocus();
expect(document.activeElement).toBe(firstMenuItem);
await user.click(firstMenuItem);
expect(trigger).toHaveFocus();
await waitFor(() => {
expect(screen.queryByText(FIRST_MENU_ITEM)).not.toBeInTheDocument();
});
Expand Down Expand Up @@ -179,6 +180,7 @@ describe("Menu behaviors", () => {
expect(firstMenuItem).toHaveFocus();
expect(document.activeElement).toBe(firstMenuItem);
await user.click(firstMenuItem);
expect(trigger).toHaveFocus();

expect(onOpenChange).toHaveBeenCalledWith(false);
});
Expand All @@ -202,6 +204,7 @@ describe("Menu behaviors", () => {
expect(firstMenuItem).toHaveFocus();
expect(document.activeElement).toBe(firstMenuItem);
await user.click(firstMenuItem);
expect(trigger).toHaveFocus();
expect(onClick).toHaveBeenCalled();
});

Expand All @@ -224,6 +227,7 @@ describe("Menu behaviors", () => {
expect(firstMenuItem).toHaveFocus();
expect(document.activeElement).toBe(firstMenuItem);
await user.click(firstMenuItem);
expect(trigger).toHaveFocus();
expect(onFocus).toHaveBeenCalled();
});

Expand Down
18 changes: 16 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9d229b0

Please sign in to comment.