From 39b164647f651e02041f632adad196f886c87517 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Fri, 5 Nov 2021 12:57:41 +0100 Subject: [PATCH] Fix `type` on `Tabs` component Vue (#912) * add `tabs` example to Vue * use useResolveButtonType for Tabs * update changelog --- CHANGELOG.md | 1 + .../examples/src/components/tabs/tabs.vue | 81 +++++++++++++++++++ .../@headlessui-vue/examples/src/routes.json | 11 +++ .../src/components/tabs/tabs.ts | 7 +- 4 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 packages/@headlessui-vue/examples/src/components/tabs/tabs.vue diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b24b7d746..2758846106 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Allow to click on elements inside a `DialogOverlay` ([#816](https://github.com/tailwindlabs/headlessui/pull/816)) - Fix SSR crash because of `useWindowEvent` ([#817](https://github.com/tailwindlabs/headlessui/pull/817)) - Improve tree shaking ([#859](https://github.com/tailwindlabs/headlessui/pull/859)) +- Add `type="button"` to `Tabs` component ([#912](https://github.com/tailwindlabs/headlessui/pull/912)) ## [@headlessui/react@v1.4.1] - 2021-08-30 diff --git a/packages/@headlessui-vue/examples/src/components/tabs/tabs.vue b/packages/@headlessui-vue/examples/src/components/tabs/tabs.vue new file mode 100644 index 0000000000..f8499b13dc --- /dev/null +++ b/packages/@headlessui-vue/examples/src/components/tabs/tabs.vue @@ -0,0 +1,81 @@ + + + diff --git a/packages/@headlessui-vue/examples/src/routes.json b/packages/@headlessui-vue/examples/src/routes.json index 1d769607e4..d1f1408eb0 100644 --- a/packages/@headlessui-vue/examples/src/routes.json +++ b/packages/@headlessui-vue/examples/src/routes.json @@ -61,6 +61,17 @@ } ] }, + { + "name": "Tabs", + "path": "/tabs", + "children": [ + { + "name": "Tabs (basic)", + "path": "/tabs/tabs", + "component": "./components/tabs/tabs.vue" + } + ] + }, { "name": "Focus Trap", "path": "/focus-trap", diff --git a/packages/@headlessui-vue/src/components/tabs/tabs.ts b/packages/@headlessui-vue/src/components/tabs/tabs.ts index 7c50ac0145..3705e8145a 100644 --- a/packages/@headlessui-vue/src/components/tabs/tabs.ts +++ b/packages/@headlessui-vue/src/components/tabs/tabs.ts @@ -16,6 +16,7 @@ import { Keys } from '../../keyboard' import { dom } from '../../utils/dom' import { match } from '../../utils/match' import { focusIn, Focus } from '../../utils/focus-management' +import { useResolveButtonType } from '../../hooks/use-resolve-button-type' type StateDefinition = { // State @@ -217,7 +218,6 @@ export let Tab = defineComponent({ let myIndex = computed(() => api.tabs.value.indexOf(tabRef)) let selected = computed(() => myIndex.value === api.selectedIndex.value) - let type = computed(() => attrs.type ?? (props.as === 'button' ? 'button' : undefined)) function handleKeyDown(event: KeyboardEvent) { let list = api.tabs.value.map(tab => dom(tab)).filter(Boolean) as HTMLElement[] @@ -276,7 +276,10 @@ export let Tab = defineComponent({ id, selected, myIndex, - type, + type: useResolveButtonType( + computed(() => ({ as: props.as, type: attrs.type })), + tabRef + ), handleKeyDown, handleFocus, handleSelection,