From 72ae295ce1d7c58743a45835556073c424060868 Mon Sep 17 00:00:00 2001 From: Maksym Portianoi Date: Fri, 25 Oct 2024 16:47:31 -0400 Subject: [PATCH] fix(ktabs): slotted anchor link (#2480) * fix(ktabs): slotted anchor link color * fix(ktabs): slotted link color * fix(ktabs): slotted anchor link active * fix(ktabs): add anchor-tabindex prop * docs(tabs): anchor-tabindex prop --- docs/components/table-view.md | 27 ++++++++++++++++---- docs/components/tabs.md | 4 +++ sandbox/pages/SandboxTabs.vue | 1 + src/components/KTabs/KTabs.vue | 46 +++++++++++++++++++++++++++------- 4 files changed, 64 insertions(+), 14 deletions(-) diff --git a/docs/components/table-view.md b/docs/components/table-view.md index 91412aa9f0..3fb96c6559 100644 --- a/docs/components/table-view.md +++ b/docs/components/table-view.md @@ -518,11 +518,28 @@ The `rowKey` prop accepts either a unique string or a function that returns a un If a string is provided which corresponds to a property of the `row`, the unique identifier will utilize the `row[rowKey]` as the unique identifier. ```html - + + + ``` Alternatively, if a function is passed, it allows for the creation of a custom identifier based on the row data passed to the function. diff --git a/docs/components/tabs.md b/docs/components/tabs.md index c6e5ba1954..f99fcfdcbc 100644 --- a/docs/components/tabs.md +++ b/docs/components/tabs.md @@ -176,6 +176,10 @@ const tabChange = (hash: string): void => { ``` +### anchorTabindex + +This prop allows setting a custom `tabindex` for the tab anchor element. It’s useful when passing a custom interactive element, like a link, through the [`anchor` slot](#anchor-panel), ensuring that only the slotted element is focusable by resetting the default anchor `tabindex`. Default value is `0`. + #### Dynamic RouterView Here's an example (code only) of utilizing a dynamic `router-view` component within the host app: diff --git a/sandbox/pages/SandboxTabs.vue b/sandbox/pages/SandboxTabs.vue index a75c2c7e47..62e9310063 100644 --- a/sandbox/pages/SandboxTabs.vue +++ b/sandbox/pages/SandboxTabs.vue @@ -111,6 +111,7 @@ /> - + {{ tab.title }} @@ -34,13 +34,13 @@ v-for="(tab, i) in tabs" :id="`panel-${i}`" :key="tab.hash" - :aria-labelledby="`${tab.hash.replace('#','')}-tab`" + :aria-labelledby="`${getTabSlotName(tab.hash)}-tab`" class="tab-container" role="tabpanel" > @@ -75,6 +75,11 @@ const props = defineProps({ type: Boolean, default: false, }, + anchorTabindex: { + type: Number, + default: 0, + validator: (val: number): boolean => val >= -1 && val <= 32767, + }, }) const emit = defineEmits<{ @@ -90,6 +95,16 @@ const handleTabChange = (tab: string): void => { emit('update:modelValue', tab) } +const getTabSlotName = (tabHash: string): string => tabHash.replace('#', '') + +const getAnchorTabindex = (tab: Tab): string => { + if (tab.disabled) { + return '-1' + } + + return typeof props.anchorTabindex === 'number' && props.anchorTabindex >= -1 && props.anchorTabindex <= 32767 ? String(props.anchorTabindex) : '0' +} + watch(() => props.modelValue, (newTabHash) => { activeTab.value = newTabHash emit('change', newTabHash) @@ -98,6 +113,14 @@ watch(() => props.modelValue, (newTabHash) => {