mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 18:31:06 +00:00
chore: v11 Tabs
In v11 [Tabs](https://carbondesignsystem.com/migrating/guide/design/#tabs-breaking) received some additional modifiers. In this commit we only want to make sure that the Svelte v10 tabs still work using v11 styles. This probably needs additional testing.
This commit is contained in:
parent
7f84c57cb9
commit
1628f56184
8 changed files with 47 additions and 146 deletions
|
@ -3945,13 +3945,11 @@ None.
|
|||
|
||||
### Props
|
||||
|
||||
| Prop name | Required | Kind | Reactive | Type | Default value | Description |
|
||||
| :-------------- | :------- | :--------------- | :------- | ----------------------------------------- | -------------------------------- | -------------------------------------------- |
|
||||
| selected | No | <code>let</code> | Yes | <code>number</code> | <code>0</code> | Specify the selected tab index |
|
||||
| type | No | <code>let</code> | No | <code>"default" | "container"</code> | <code>"default"</code> | Specify the type of tabs |
|
||||
| autoWidth | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` for tabs to have an auto-width |
|
||||
| iconDescription | No | <code>let</code> | No | <code>string</code> | <code>"Show menu options"</code> | Specify the ARIA label for the chevron icon |
|
||||
| triggerHref | No | <code>let</code> | No | <code>string</code> | <code>"#"</code> | Specify the tab trigger href attribute |
|
||||
| Prop name | Required | Kind | Reactive | Type | Default value | Description |
|
||||
| :-------- | :------- | :--------------- | :------- | -------------------- | ------------------ | -------------------------------------------- |
|
||||
| selected | No | <code>let</code> | Yes | <code>number</code> | <code>0</code> | Specify the selected tab index |
|
||||
| contained | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` for tabs to be contained |
|
||||
| autoWidth | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` for tabs to have an auto-width |
|
||||
|
||||
### Slots
|
||||
|
||||
|
@ -3964,8 +3962,6 @@ None.
|
|||
|
||||
| Event name | Type | Detail |
|
||||
| :--------- | :--------- | :----- |
|
||||
| keypress | forwarded | -- |
|
||||
| click | forwarded | -- |
|
||||
| change | dispatched | -- |
|
||||
|
||||
## `TabsSkeleton`
|
||||
|
|
|
@ -11856,13 +11856,13 @@
|
|||
}
|
||||
],
|
||||
"events": [
|
||||
{ "type": "forwarded", "name": "click", "element": "li" },
|
||||
{ "type": "forwarded", "name": "mouseover", "element": "li" },
|
||||
{ "type": "forwarded", "name": "mouseenter", "element": "li" },
|
||||
{ "type": "forwarded", "name": "mouseleave", "element": "li" }
|
||||
{ "type": "forwarded", "name": "click", "element": "a" },
|
||||
{ "type": "forwarded", "name": "mouseover", "element": "a" },
|
||||
{ "type": "forwarded", "name": "mouseenter", "element": "a" },
|
||||
{ "type": "forwarded", "name": "mouseleave", "element": "a" }
|
||||
],
|
||||
"typedefs": [],
|
||||
"rest_props": { "type": "Element", "name": "li" }
|
||||
"rest_props": { "type": "Element", "name": "a" }
|
||||
},
|
||||
{
|
||||
"moduleName": "TabContent",
|
||||
|
@ -12187,11 +12187,11 @@
|
|||
"reactive": true
|
||||
},
|
||||
{
|
||||
"name": "type",
|
||||
"name": "contained",
|
||||
"kind": "let",
|
||||
"description": "Specify the type of tabs",
|
||||
"type": "\"default\" | \"container\"",
|
||||
"value": "\"default\"",
|
||||
"description": "Set to `true` for tabs to be contained",
|
||||
"type": "boolean",
|
||||
"value": "false",
|
||||
"isFunction": false,
|
||||
"isFunctionDeclaration": false,
|
||||
"isRequired": false,
|
||||
|
@ -12209,30 +12209,6 @@
|
|||
"isRequired": false,
|
||||
"constant": false,
|
||||
"reactive": false
|
||||
},
|
||||
{
|
||||
"name": "iconDescription",
|
||||
"kind": "let",
|
||||
"description": "Specify the ARIA label for the chevron icon",
|
||||
"type": "string",
|
||||
"value": "\"Show menu options\"",
|
||||
"isFunction": false,
|
||||
"isFunctionDeclaration": false,
|
||||
"isRequired": false,
|
||||
"constant": false,
|
||||
"reactive": false
|
||||
},
|
||||
{
|
||||
"name": "triggerHref",
|
||||
"kind": "let",
|
||||
"description": "Specify the tab trigger href attribute",
|
||||
"type": "string",
|
||||
"value": "\"#\"",
|
||||
"isFunction": false,
|
||||
"isFunctionDeclaration": false,
|
||||
"isRequired": false,
|
||||
"constant": false,
|
||||
"reactive": false
|
||||
}
|
||||
],
|
||||
"moduleExports": [],
|
||||
|
@ -12240,11 +12216,7 @@
|
|||
{ "name": "__default__", "default": true, "slot_props": "{}" },
|
||||
{ "name": "content", "default": false, "slot_props": "{}" }
|
||||
],
|
||||
"events": [
|
||||
{ "type": "forwarded", "name": "keypress", "element": "div" },
|
||||
{ "type": "forwarded", "name": "click", "element": "a" },
|
||||
{ "type": "dispatched", "name": "change" }
|
||||
],
|
||||
"events": [{ "type": "dispatched", "name": "change" }],
|
||||
"typedefs": [],
|
||||
"rest_props": { "type": "Element", "name": "div" }
|
||||
},
|
||||
|
|
|
@ -60,9 +60,9 @@ Using keyboard navigation (left and right arrow keys) will skip to the next non-
|
|||
</svelte:fragment>
|
||||
</Tabs>
|
||||
|
||||
## Container type
|
||||
## Contained
|
||||
|
||||
<Tabs type="container">
|
||||
<Tabs contained>
|
||||
<Tab label="Tab label 1" />
|
||||
<Tab label="Tab label 2" />
|
||||
<Tab label="Tab label 3" />
|
||||
|
@ -77,6 +77,6 @@ Using keyboard navigation (left and right arrow keys) will skip to the next non-
|
|||
|
||||
<TabsSkeleton count={3} />
|
||||
|
||||
## Skeleton (container)
|
||||
## Skeleton (contained)
|
||||
|
||||
<TabsSkeleton type="container" count={3} />
|
||||
<TabsSkeleton contained count={3} />
|
|
@ -30,12 +30,19 @@
|
|||
</script>
|
||||
|
||||
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
|
||||
<li
|
||||
tabindex="-1"
|
||||
role="presentation"
|
||||
<a
|
||||
bind:this="{ref}"
|
||||
tabindex="{disabled ? '-1' : tabindex}"
|
||||
role="tab"
|
||||
class:bx--tabs__nav-item="{true}"
|
||||
class:bx--tabs__nav-link="{true}"
|
||||
class:bx--tabs__nav-item--disabled="{disabled}"
|
||||
class:bx--tabs__nav-item--selected="{selected}"
|
||||
aria-selected="{selected}"
|
||||
aria-disabled="{disabled}"
|
||||
id="{id}"
|
||||
href="{href}"
|
||||
style="{$useAutoWidth ? 'width: auto' : undefined}"
|
||||
{...$$restProps}
|
||||
on:click|preventDefault
|
||||
on:click|preventDefault="{() => {
|
||||
|
@ -58,17 +65,5 @@
|
|||
}
|
||||
}}"
|
||||
>
|
||||
<a
|
||||
bind:this="{ref}"
|
||||
role="tab"
|
||||
tabindex="{disabled ? '-1' : tabindex}"
|
||||
aria-selected="{selected}"
|
||||
aria-disabled="{disabled}"
|
||||
id="{id}"
|
||||
href="{href}"
|
||||
class:bx--tabs__nav-link="{true}"
|
||||
style:width="{$useAutoWidth ? "auto" : undefined}"
|
||||
>
|
||||
<slot>{label}</slot>
|
||||
</a>
|
||||
</li>
|
||||
<slot>{label}</slot>
|
||||
</a>
|
||||
|
|
|
@ -3,26 +3,15 @@
|
|||
export let selected = 0;
|
||||
|
||||
/**
|
||||
* Specify the type of tabs
|
||||
* @type {"default" | "container"}
|
||||
* Set to `true` for tabs to be contained
|
||||
*/
|
||||
export let type = "default";
|
||||
export let contained = false;
|
||||
|
||||
/** Set to `true` for tabs to have an auto-width */
|
||||
export let autoWidth = false;
|
||||
|
||||
/**
|
||||
* Specify the ARIA label for the chevron icon
|
||||
* @type {string}
|
||||
*/
|
||||
export let iconDescription = "Show menu options";
|
||||
|
||||
/** Specify the tab trigger href attribute */
|
||||
export let triggerHref = "#";
|
||||
|
||||
import { createEventDispatcher, afterUpdate, setContext, tick } from "svelte";
|
||||
import { writable, derived } from "svelte/store";
|
||||
import ChevronDown from "../icons/ChevronDown.svelte";
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
|
@ -122,43 +111,11 @@
|
|||
<div
|
||||
role="navigation"
|
||||
class:bx--tabs="{true}"
|
||||
class:bx--tabs--container="{type === 'container'}"
|
||||
class:bx--tabs--contained="{contained}"
|
||||
{...$$restProps}
|
||||
>
|
||||
<div
|
||||
role="listbox"
|
||||
tabindex="0"
|
||||
class:bx--tabs-trigger="{true}"
|
||||
aria-label="{$$props['aria-label'] || 'listbox'}"
|
||||
on:click="{() => {
|
||||
dropdownHidden = !dropdownHidden;
|
||||
}}"
|
||||
on:keypress
|
||||
on:keypress="{() => {
|
||||
dropdownHidden = !dropdownHidden;
|
||||
}}"
|
||||
>
|
||||
<a
|
||||
tabindex="-1"
|
||||
class:bx--tabs-trigger-text="{true}"
|
||||
href="{triggerHref}"
|
||||
on:click|preventDefault
|
||||
on:click|preventDefault|stopPropagation="{() => {
|
||||
dropdownHidden = !dropdownHidden;
|
||||
}}"
|
||||
>
|
||||
{#if currentTab}{currentTab.label}{/if}
|
||||
</a>
|
||||
<ChevronDown aria-hidden="true" title="{iconDescription}" />
|
||||
</div>
|
||||
<!-- svelte-ignore a11y-no-noninteractive-element-to-interactive-role -->
|
||||
<ul
|
||||
bind:this="{refTabList}"
|
||||
role="tablist"
|
||||
class:bx--tabs__nav="{true}"
|
||||
class:bx--tabs__nav--hidden="{dropdownHidden}"
|
||||
>
|
||||
<div bind:this="{refTabList}" role="tablist" class:bx--tab--list="{true}">
|
||||
<slot />
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<slot name="content" />
|
||||
|
|
|
@ -14,21 +14,18 @@
|
|||
<div
|
||||
class:bx--tabs="{true}"
|
||||
class:bx--skeleton="{true}"
|
||||
class:bx--tabs--scrollable="{true}"
|
||||
class:bx--tabs--scrollable--container="{type === 'container'}"
|
||||
class:bx--tabs--contained="{type === 'container'}"
|
||||
{...$$restProps}
|
||||
on:click
|
||||
on:mouseover
|
||||
on:mouseenter
|
||||
on:mouseleave
|
||||
>
|
||||
<ul class:bx--tabs--scrollable__nav="{true}">
|
||||
<div class:bx--tab--list="{true}">
|
||||
{#each Array.from({ length: count }, (_, i) => i) as item}
|
||||
<li class:bx--tabs--scrollable__nav-item="{true}">
|
||||
<div class:bx--tabs__nav-link="{true}">
|
||||
<span></span>
|
||||
</div>
|
||||
</li>
|
||||
<span class:bx--tabs__nav-item="{true}" class:bx--tabs__nav-link="{true}">
|
||||
<span></span>
|
||||
</span>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
2
types/Tabs/Tab.svelte.d.ts
vendored
2
types/Tabs/Tab.svelte.d.ts
vendored
|
@ -1,7 +1,7 @@
|
|||
import type { SvelteComponentTyped } from "svelte";
|
||||
import type { SvelteHTMLElements } from "svelte/elements";
|
||||
|
||||
type RestProps = SvelteHTMLElements["li"];
|
||||
type RestProps = SvelteHTMLElements["a"];
|
||||
|
||||
export interface TabProps extends RestProps {
|
||||
/**
|
||||
|
|
24
types/Tabs/Tabs.svelte.d.ts
vendored
24
types/Tabs/Tabs.svelte.d.ts
vendored
|
@ -11,10 +11,10 @@ export interface TabsProps extends RestProps {
|
|||
selected?: number;
|
||||
|
||||
/**
|
||||
* Specify the type of tabs
|
||||
* @default "default"
|
||||
* Set to `true` for tabs to be contained
|
||||
* @default false
|
||||
*/
|
||||
type?: "default" | "container";
|
||||
contained?: boolean;
|
||||
|
||||
/**
|
||||
* Set to `true` for tabs to have an auto-width
|
||||
|
@ -22,27 +22,11 @@ export interface TabsProps extends RestProps {
|
|||
*/
|
||||
autoWidth?: boolean;
|
||||
|
||||
/**
|
||||
* Specify the ARIA label for the chevron icon
|
||||
* @default "Show menu options"
|
||||
*/
|
||||
iconDescription?: string;
|
||||
|
||||
/**
|
||||
* Specify the tab trigger href attribute
|
||||
* @default "#"
|
||||
*/
|
||||
triggerHref?: string;
|
||||
|
||||
[key: `data-${string}`]: any;
|
||||
}
|
||||
|
||||
export default class Tabs extends SvelteComponentTyped<
|
||||
TabsProps,
|
||||
{
|
||||
keypress: WindowEventMap["keypress"];
|
||||
click: WindowEventMap["click"];
|
||||
change: CustomEvent<any>;
|
||||
},
|
||||
{ change: CustomEvent<any> },
|
||||
{ default: {}; content: {} }
|
||||
> {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue