Skip to content

Commit d705db4

Browse files
committed
feat(headless/tabs): add disabled to TabPanel
For the "short version" it's now possible to add `disabled` prop to disable the tab
1 parent cdf13c8 commit d705db4

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

packages/kit-headless/src/components/tabs/tab-panel.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type TabPanelProps = {
1414
/** Optional tab contents. */
1515
label?: QwikIntrinsicElements['div']['children'];
1616
selected?: boolean;
17+
disabled?: boolean;
1718

1819
/** @deprecated Internal use only */
1920
_tabId?: string;

packages/kit-headless/src/components/tabs/tabs.spec.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,8 @@ describe('Tabs', () => {
541541
});
542542

543543
it(`GIVEN 5 tabs with tab 3 selected and tabs 3-5 are disabled
544-
WHEN loading the component
545-
THEN the selected tab should be the second tab`, () => {
544+
WHEN loading the component
545+
THEN the selected tab should be the second tab`, () => {
546546
cy.mount(
547547
<Tabs selectedIndex={2}>
548548
<TabList>
@@ -563,7 +563,23 @@ describe('Tabs', () => {
563563
cy.findByRole('tabpanel').should('contain', 'Panel 2');
564564
});
565565

566-
it(`GIVEN 1 disabled tab
566+
it.only(`GIVEN 3 tabs written with the short version and the middle TabPanel has a disabled prop
567+
WHEN focusing on first component and hitting the right key
568+
THEN the selected tab should be the third one`, () => {
569+
cy.mount(
570+
<Tabs>
571+
<TabPanel label="Tab 1">Panel 1</TabPanel>
572+
<TabPanel label="Tab 2" disabled>
573+
Panel 2
574+
</TabPanel>
575+
<TabPanel label="Tab 3">Panel 3</TabPanel>
576+
</Tabs>
577+
);
578+
cy.findByRole('tab', { name: /Tab 1/i }).type('{rightarrow}');
579+
cy.findByRole('tab', { name: /Tab 3/i }).should('have.focus');
580+
});
581+
582+
it(`GIVEN 3 disabled tab
567583
WHEN loading the component
568584
THEN no panel or tab should be selected`, () => {
569585
cy.mount(

packages/kit-headless/src/components/tabs/tabs.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ export const Tabs: FunctionComponent<TabsProps> = (props) => {
159159
tab.key = tabId;
160160
tab.props.tabId = tabId;
161161
tab.props._extraClass = tabClass;
162+
if (
163+
tabInfoList[index].panelProps.disabled !== undefined &&
164+
tab.props.disabled === undefined
165+
) {
166+
tab.props.disabled = tabInfoList[index].panelProps.disabled;
167+
}
162168
tabInfoList[index].tabProps = tab.props;
163169
});
164170

0 commit comments

Comments
 (0)