mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
fix(toggle): add missing hideLabel
prop (#1414)
* fix(toggle): add missing hideLabel prop * Run "yarn build:docs" * test(toggle): assert hideLabel prop * docs(toggle): add "Hidden label text" example
This commit is contained in:
parent
614e6eb087
commit
f4d12b805a
6 changed files with 34 additions and 4 deletions
|
@ -4347,6 +4347,7 @@ export type CarbonTheme = "white" | "g10" | "g80" | "g90" | "g100";
|
||||||
| labelA | No | <code>let</code> | No | <code>string</code> | <code>"Off"</code> | Specify the label for the untoggled state |
|
| labelA | No | <code>let</code> | No | <code>string</code> | <code>"Off"</code> | Specify the label for the untoggled state |
|
||||||
| labelB | No | <code>let</code> | No | <code>string</code> | <code>"On"</code> | Specify the label for the toggled state |
|
| labelB | No | <code>let</code> | No | <code>string</code> | <code>"On"</code> | Specify the label for the toggled state |
|
||||||
| labelText | No | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the label text |
|
| labelText | No | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the label text |
|
||||||
|
| hideLabel | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to visually hide the label text |
|
||||||
| id | No | <code>let</code> | No | <code>string</code> | <code>"ccs-" + Math.random().toString(36)</code> | Set an id for the input element |
|
| id | No | <code>let</code> | No | <code>string</code> | <code>"ccs-" + Math.random().toString(36)</code> | Set an id for the input element |
|
||||||
| name | No | <code>let</code> | No | <code>string</code> | <code>undefined</code> | Specify a name attribute for the checkbox input |
|
| name | No | <code>let</code> | No | <code>string</code> | <code>undefined</code> | Specify a name attribute for the checkbox input |
|
||||||
|
|
||||||
|
|
|
@ -13494,6 +13494,18 @@
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"reactive": false
|
"reactive": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "hideLabel",
|
||||||
|
"kind": "let",
|
||||||
|
"description": "Set to `true` to visually hide the label text",
|
||||||
|
"type": "boolean",
|
||||||
|
"value": "false",
|
||||||
|
"isFunction": false,
|
||||||
|
"isFunctionDeclaration": false,
|
||||||
|
"isRequired": false,
|
||||||
|
"constant": false,
|
||||||
|
"reactive": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "id",
|
"name": "id",
|
||||||
"kind": "let",
|
"kind": "let",
|
||||||
|
|
|
@ -23,6 +23,12 @@ components: ["Toggle", "ToggleSkeleton"]
|
||||||
|
|
||||||
<Toggle labelText="Push notifications" on:toggle={e => console.log(e.detail)} />
|
<Toggle labelText="Push notifications" on:toggle={e => console.log(e.detail)} />
|
||||||
|
|
||||||
|
### Hidden label text
|
||||||
|
|
||||||
|
Set `hideLabel` to `true` to visually hide the label text. It's recommended to still specify `labelText` for screen reader accessibility.
|
||||||
|
|
||||||
|
<Toggle labelText="Push notifications" hideLabel />
|
||||||
|
|
||||||
### Custom labels
|
### Custom labels
|
||||||
|
|
||||||
<Toggle labelText="Push notifications" labelA="No" labelB="Yes" />
|
<Toggle labelText="Push notifications" labelA="No" labelB="Yes" />
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
/** Specify the label text */
|
/** Specify the label text */
|
||||||
export let labelText = "";
|
export let labelText = "";
|
||||||
|
|
||||||
|
/** Set to `true` to visually hide the label text */
|
||||||
|
export let hideLabel = false;
|
||||||
|
|
||||||
/** Set an id for the input element */
|
/** Set an id for the input element */
|
||||||
export let id = "ccs-" + Math.random().toString(36);
|
export let id = "ccs-" + Math.random().toString(36);
|
||||||
|
|
||||||
|
@ -76,9 +79,11 @@
|
||||||
for="{id}"
|
for="{id}"
|
||||||
class:bx--toggle-input__label="{true}"
|
class:bx--toggle-input__label="{true}"
|
||||||
>
|
>
|
||||||
|
<span class:bx--visually-hidden="{hideLabel}">
|
||||||
<slot name="labelText">
|
<slot name="labelText">
|
||||||
{labelText}
|
{labelText}
|
||||||
</slot>
|
</slot>
|
||||||
|
</span>
|
||||||
<span class:bx--toggle__switch="{true}">
|
<span class:bx--toggle__switch="{true}">
|
||||||
<span aria-hidden="true" class:bx--toggle__text--off="{true}">
|
<span aria-hidden="true" class:bx--toggle__text--off="{true}">
|
||||||
<slot name="labelA">
|
<slot name="labelA">
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import { Toggle, ToggleSkeleton } from "../types";
|
import { Toggle, ToggleSkeleton } from "../types";
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Toggle labelText="Push notifications" />
|
<Toggle labelText="Push notifications" hideLabel />
|
||||||
|
|
||||||
<Toggle
|
<Toggle
|
||||||
labelText="Push notifications"
|
labelText="Push notifications"
|
||||||
|
|
6
types/Toggle/Toggle.svelte.d.ts
vendored
6
types/Toggle/Toggle.svelte.d.ts
vendored
|
@ -39,6 +39,12 @@ export interface ToggleProps
|
||||||
*/
|
*/
|
||||||
labelText?: string;
|
labelText?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to `true` to visually hide the label text
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
hideLabel?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set an id for the input element
|
* Set an id for the input element
|
||||||
* @default "ccs-" + Math.random().toString(36)
|
* @default "ccs-" + Math.random().toString(36)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue