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:
metonym 2022-07-26 07:12:57 -07:00 committed by GitHub
commit f4d12b805a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 4 deletions

View file

@ -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 |

View file

@ -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",

View file

@ -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" />

View file

@ -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}"
> >
<slot name="labelText"> <span class:bx--visually-hidden="{hideLabel}">
{labelText} <slot name="labelText">
</slot> {labelText}
</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">

View file

@ -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"

View file

@ -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)