Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ktabs): disabled item remove pointer events none [KHCP-11265] #2103

Merged
merged 2 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sandbox/pages/SandboxTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
3
</KBadge>
</template>
<template #disabled-anchor>
<KTooltip text="This tab item is disabled.">
<div>Disabled</div>
</KTooltip>
</template>

<template #tab1>
Tab 1 content
Expand Down
21 changes: 21 additions & 0 deletions src/components/KTabs/KTabs.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,27 @@ describe('KTabs', () => {
})
})

// handles disabled item correctly

it('disables the tab item when `disabled` is true', () => {
const tabs = [
{ hash: '#pictures', title: 'Pictures' },
{ hash: '#movies', title: 'Movies', disabled: true },
{ hash: '#books', title: 'Books' },
]

mount(KTabs, {
props: {
tabs,
},
})

cy.get('.tab-item .tab-link').eq(1).should('have.class', 'disabled')
cy.get('.tab-item').eq(1).click().then(() => {
cy.wrap(Cypress.vueWrapper.emitted()).should('not.have.property', 'change')
})
})

describe('slots', () => {
it('provides the #hash slot content', () => {
const picturesSlot = 'I love pictures'
Expand Down
24 changes: 10 additions & 14 deletions src/components/KTabs/KTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
:id="`${tab.hash.replace('#','')}-tab`"
:key="tab.hash"
class="tab-item"
:class="{ active: activeTab === tab.hash, disabled: tab.disabled }"
:class="{ active: activeTab === tab.hash }"
>
<div
:aria-controls="hidePanels ? undefined : `panel-${tab.hash}`"
:aria-selected="hidePanels ? undefined : (activeTab === tab.hash ? 'true' : 'false')"
class="tab-link"
:class="{ 'has-panels': !hidePanels }"
:class="{ 'has-panels': !hidePanels, disabled: tab.disabled }"
role="tab"
:tabindex="tab.disabled ? '-1' : '0'"
@click.prevent="handleTabChange(tab.hash)"
@keydown.enter.prevent="handleTabChange(tab.hash)"
@keydown.space.prevent="handleTabChange(tab.hash)"
@click.prevent="!tab.disabled ? handleTabChange(tab.hash) : undefined"
@keydown.enter.prevent="!tab.disabled ? handleTabChange(tab.hash) : undefined"
@keydown.space.prevent="!tab.disabled ? handleTabChange(tab.hash) : undefined"
>
<slot :name="`${tab.hash.replace('#','')}-anchor`">
<span>{{ tab.title }}</span>
Expand Down Expand Up @@ -155,6 +155,11 @@ watch(() => props.modelValue, (newTabHash) => {
color: var(--kui-color-text, $kui-color-text);
outline: none;
}

&.disabled {
color: var(--kui-color-text-disabled, $kui-color-text-disabled);
cursor: not-allowed;
}
}

&.active {
Expand All @@ -164,15 +169,6 @@ watch(() => props.modelValue, (newTabHash) => {
color: var(--kui-color-text, $kui-color-text);
}
}

&.disabled {
cursor: not-allowed;

.tab-link {
color: var(--kui-color-text-disabled, $kui-color-text-disabled);
pointer-events: none;
}
}
}
}
}
Expand Down
Loading