Skip to content

Commit ec84c72

Browse files
authored
Fix scrolling issue in Tab component when using arrow keys (#1584)
* prevent scrolling the page when using arrow keys in * update changelog * bump prettier Does GitHub Actions have an incorrect cache somehow? * use Active LTS in CI
1 parent ea5f21a commit ec84c72

File tree

7 files changed

+41
-30
lines changed

7 files changed

+41
-30
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ concurrency:
77
cancel-in-progress: true
88

99
env:
10-
NODE_VERSION: 12.x
10+
NODE_VERSION: 16.x
1111

1212
jobs:
1313
install:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"jest": "26",
4848
"lint-staged": "^12.2.1",
4949
"npm-run-all": "^4.1.5",
50-
"prettier": "^2.5.1",
50+
"prettier": "^2.6.2",
5151
"prettier-plugin-tailwindcss": "^0.1.4",
5252
"rimraf": "^3.0.2",
5353
"tslib": "^2.3.1",

packages/@headlessui-react/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- Improve outside click of `Dialog` component ([#1546](https://github.com/tailwindlabs/headlessui/pull/1546))
1919
- Detect outside clicks from within `<iframe>` elements ([#1552](https://github.com/tailwindlabs/headlessui/pull/1552))
2020
- Improve Combobox input cursor position ([#1574](https://github.com/tailwindlabs/headlessui/pull/1574))
21+
- Fix scrolling issue in `Tab` component when using arrow keys ([#1584](https://github.com/tailwindlabs/headlessui/pull/1584))
2122

2223
## [1.6.4] - 2022-05-29
2324

packages/@headlessui-react/src/components/tabs/tabs.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -366,18 +366,22 @@ let TabRoot = forwardRefWithAs(function Tab<TTag extends ElementType = typeof DE
366366
return focusIn(list, Focus.Last)
367367
}
368368

369-
return match(orientation, {
370-
vertical() {
371-
if (event.key === Keys.ArrowUp) return focusIn(list, Focus.Previous | Focus.WrapAround)
372-
if (event.key === Keys.ArrowDown) return focusIn(list, Focus.Next | Focus.WrapAround)
373-
return
374-
},
375-
horizontal() {
376-
if (event.key === Keys.ArrowLeft) return focusIn(list, Focus.Previous | Focus.WrapAround)
377-
if (event.key === Keys.ArrowRight) return focusIn(list, Focus.Next | Focus.WrapAround)
378-
return
379-
},
380-
})
369+
if (
370+
match(orientation, {
371+
vertical() {
372+
if (event.key === Keys.ArrowUp) return focusIn(list, Focus.Previous | Focus.WrapAround)
373+
if (event.key === Keys.ArrowDown) return focusIn(list, Focus.Next | Focus.WrapAround)
374+
return
375+
},
376+
horizontal() {
377+
if (event.key === Keys.ArrowLeft) return focusIn(list, Focus.Previous | Focus.WrapAround)
378+
if (event.key === Keys.ArrowRight) return focusIn(list, Focus.Next | Focus.WrapAround)
379+
return
380+
},
381+
})
382+
) {
383+
return event.preventDefault()
384+
}
381385
})
382386

383387
let handleFocus = useEvent(() => {

packages/@headlessui-vue/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
- Detect outside clicks from within `<iframe>` elements ([#1552](https://github.com/tailwindlabs/headlessui/pull/1552))
2020
- Only render the `Dialog` on the client ([#1566](https://github.com/tailwindlabs/headlessui/pull/1566))
2121
- Improve Combobox input cursor position ([#1574](https://github.com/tailwindlabs/headlessui/pull/1574))
22+
- Fix scrolling issue in `Tab` component when using arrow keys ([#1584](https://github.com/tailwindlabs/headlessui/pull/1584))
2223

2324
## [1.6.4] - 2022-05-29
2425

packages/@headlessui-vue/src/components/tabs/tabs.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -247,18 +247,23 @@ export let Tab = defineComponent({
247247
return focusIn(list, Focus.Last)
248248
}
249249

250-
return match(api.orientation.value, {
251-
vertical() {
252-
if (event.key === Keys.ArrowUp) return focusIn(list, Focus.Previous | Focus.WrapAround)
253-
if (event.key === Keys.ArrowDown) return focusIn(list, Focus.Next | Focus.WrapAround)
254-
return
255-
},
256-
horizontal() {
257-
if (event.key === Keys.ArrowLeft) return focusIn(list, Focus.Previous | Focus.WrapAround)
258-
if (event.key === Keys.ArrowRight) return focusIn(list, Focus.Next | Focus.WrapAround)
259-
return
260-
},
261-
})
250+
if (
251+
match(api.orientation.value, {
252+
vertical() {
253+
if (event.key === Keys.ArrowUp) return focusIn(list, Focus.Previous | Focus.WrapAround)
254+
if (event.key === Keys.ArrowDown) return focusIn(list, Focus.Next | Focus.WrapAround)
255+
return
256+
},
257+
horizontal() {
258+
if (event.key === Keys.ArrowLeft)
259+
return focusIn(list, Focus.Previous | Focus.WrapAround)
260+
if (event.key === Keys.ArrowRight) return focusIn(list, Focus.Next | Focus.WrapAround)
261+
return
262+
},
263+
})
264+
) {
265+
return event.preventDefault()
266+
}
262267
}
263268

264269
function handleFocus() {

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4326,10 +4326,10 @@ prettier-plugin-tailwindcss@^0.1.4:
43264326
resolved "https://registry.yarnpkg.com/prettier-plugin-tailwindcss/-/prettier-plugin-tailwindcss-0.1.8.tgz#ba0f606ed91959ede670303d905b99106e9e6293"
43274327
integrity sha512-hwarSBCswAXa+kqYtaAkFr3Vop9o04WOyZs0qo3NyvW8L7f1rif61wRyq0+ArmVThOuRBcJF5hjGXYk86cwemg==
43284328

4329-
prettier@^2.5.1:
4330-
version "2.5.1"
4331-
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.5.1.tgz#fff75fa9d519c54cf0fce328c1017d94546bc56a"
4332-
integrity sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg==
4329+
prettier@^2.6.2:
4330+
version "2.6.2"
4331+
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.6.2.tgz#e26d71a18a74c3d0f0597f55f01fb6c06c206032"
4332+
integrity sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew==
43334333

43344334
pretty-format@^26.1.0, pretty-format@^26.6.2:
43354335
version "26.6.2"

0 commit comments

Comments
 (0)