From 274f8b76d7e20bdd7ff62571c0ce4ccce69500e6 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Mon, 13 Jun 2022 13:09:05 +0200 Subject: [PATCH 1/4] prevent scrolling the page when using arrow keys in --- .../src/components/tabs/tabs.tsx | 28 ++++++++++-------- .../src/components/tabs/tabs.ts | 29 +++++++++++-------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/packages/@headlessui-react/src/components/tabs/tabs.tsx b/packages/@headlessui-react/src/components/tabs/tabs.tsx index cf8334017..01ce338ca 100644 --- a/packages/@headlessui-react/src/components/tabs/tabs.tsx +++ b/packages/@headlessui-react/src/components/tabs/tabs.tsx @@ -366,18 +366,22 @@ let TabRoot = forwardRefWithAs(function Tab { diff --git a/packages/@headlessui-vue/src/components/tabs/tabs.ts b/packages/@headlessui-vue/src/components/tabs/tabs.ts index afe6d4ea6..3699a3786 100644 --- a/packages/@headlessui-vue/src/components/tabs/tabs.ts +++ b/packages/@headlessui-vue/src/components/tabs/tabs.ts @@ -247,18 +247,23 @@ export let Tab = defineComponent({ return focusIn(list, Focus.Last) } - return match(api.orientation.value, { - vertical() { - if (event.key === Keys.ArrowUp) return focusIn(list, Focus.Previous | Focus.WrapAround) - if (event.key === Keys.ArrowDown) return focusIn(list, Focus.Next | Focus.WrapAround) - return - }, - horizontal() { - if (event.key === Keys.ArrowLeft) return focusIn(list, Focus.Previous | Focus.WrapAround) - if (event.key === Keys.ArrowRight) return focusIn(list, Focus.Next | Focus.WrapAround) - return - }, - }) + if ( + match(api.orientation.value, { + vertical() { + if (event.key === Keys.ArrowUp) return focusIn(list, Focus.Previous | Focus.WrapAround) + if (event.key === Keys.ArrowDown) return focusIn(list, Focus.Next | Focus.WrapAround) + return + }, + horizontal() { + if (event.key === Keys.ArrowLeft) + return focusIn(list, Focus.Previous | Focus.WrapAround) + if (event.key === Keys.ArrowRight) return focusIn(list, Focus.Next | Focus.WrapAround) + return + }, + }) + ) { + return event.preventDefault() + } } function handleFocus() { From f5574e919eb972a3cf21410d9bfd1eed74f3cda5 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Mon, 13 Jun 2022 13:12:15 +0200 Subject: [PATCH 2/4] update changelog --- packages/@headlessui-react/CHANGELOG.md | 1 + packages/@headlessui-vue/CHANGELOG.md | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/@headlessui-react/CHANGELOG.md b/packages/@headlessui-react/CHANGELOG.md index afb18d99c..b0bbeaa43 100644 --- a/packages/@headlessui-react/CHANGELOG.md +++ b/packages/@headlessui-react/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Improve outside click of `Dialog` component ([#1546](https://github.com/tailwindlabs/headlessui/pull/1546)) - Detect outside clicks from within `