mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 19:46:36 +00:00
feat(tile): support disabled state for SelectableTile, RadioTile
Closes #539
This commit is contained in:
parent
50b93c8a17
commit
e5d123eb4b
8 changed files with 81 additions and 5 deletions
|
@ -2946,6 +2946,7 @@ None.
|
||||||
| :-------------- | :--------------- | :------- | :------------------- | ------------------------------------------------ | -------------------------------------------------------- |
|
| :-------------- | :--------------- | :------- | :------------------- | ------------------------------------------------ | -------------------------------------------------------- |
|
||||||
| checked | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to check the tile |
|
| checked | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to check the tile |
|
||||||
| light | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to enable the light variant |
|
| light | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to enable the light variant |
|
||||||
|
| disabled | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to disable the tile |
|
||||||
| value | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the value of the radio input |
|
| value | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the value of the radio input |
|
||||||
| tabindex | <code>let</code> | No | <code>string</code> | <code>"0"</code> | Specify the tabindex |
|
| tabindex | <code>let</code> | No | <code>string</code> | <code>"0"</code> | Specify the tabindex |
|
||||||
| iconDescription | <code>let</code> | No | <code>string</code> | <code>"Tile checkmark"</code> | Specify the ARIA label for the radio tile checkmark icon |
|
| iconDescription | <code>let</code> | No | <code>string</code> | <code>"Tile checkmark"</code> | Specify the ARIA label for the radio tile checkmark icon |
|
||||||
|
@ -3159,6 +3160,7 @@ None.
|
||||||
| ref | <code>let</code> | Yes | <code>null | HTMLInputElement</code> | <code>null</code> | Obtain a reference to the input HTML element |
|
| ref | <code>let</code> | Yes | <code>null | HTMLInputElement</code> | <code>null</code> | Obtain a reference to the input HTML element |
|
||||||
| selected | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to select the tile |
|
| selected | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to select the tile |
|
||||||
| light | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to enable the light variant |
|
| light | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to enable the light variant |
|
||||||
|
| disabled | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to disable the tile |
|
||||||
| title | <code>let</code> | No | <code>string</code> | <code>"title"</code> | Specify the title of the selectable tile |
|
| title | <code>let</code> | No | <code>string</code> | <code>"title"</code> | Specify the title of the selectable tile |
|
||||||
| value | <code>let</code> | No | <code>string</code> | <code>"value"</code> | Specify the value of the selectable tile |
|
| value | <code>let</code> | No | <code>string</code> | <code>"value"</code> | Specify the value of the selectable tile |
|
||||||
| tabindex | <code>let</code> | No | <code>string</code> | <code>"0"</code> | Specify the tabindex |
|
| tabindex | <code>let</code> | No | <code>string</code> | <code>"0"</code> | Specify the tabindex |
|
||||||
|
|
|
@ -7523,6 +7523,16 @@
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"reactive": false
|
"reactive": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "disabled",
|
||||||
|
"kind": "let",
|
||||||
|
"description": "Set to `true` to disable the tile",
|
||||||
|
"type": "boolean",
|
||||||
|
"value": "false",
|
||||||
|
"isFunction": false,
|
||||||
|
"constant": false,
|
||||||
|
"reactive": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "value",
|
"name": "value",
|
||||||
"kind": "let",
|
"kind": "let",
|
||||||
|
@ -8176,6 +8186,16 @@
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"reactive": false
|
"reactive": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "disabled",
|
||||||
|
"kind": "let",
|
||||||
|
"description": "Set to `true` to disable the tile",
|
||||||
|
"type": "boolean",
|
||||||
|
"value": "false",
|
||||||
|
"isFunction": false,
|
||||||
|
"constant": false,
|
||||||
|
"reactive": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "title",
|
"name": "title",
|
||||||
"kind": "let",
|
"kind": "let",
|
||||||
|
|
|
@ -34,3 +34,17 @@ components: ["TileGroup", "RadioTile"]
|
||||||
Plus plan
|
Plus plan
|
||||||
</RadioTile>
|
</RadioTile>
|
||||||
</TileGroup>
|
</TileGroup>
|
||||||
|
|
||||||
|
### Disabled state
|
||||||
|
|
||||||
|
<TileGroup legend="Service pricing tiers">
|
||||||
|
<RadioTile value="0" checked>
|
||||||
|
Lite plan
|
||||||
|
</RadioTile>
|
||||||
|
<RadioTile value="1" disabled>
|
||||||
|
Standard plan
|
||||||
|
</RadioTile>
|
||||||
|
<RadioTile value="2" disabled>
|
||||||
|
Plus plan
|
||||||
|
</RadioTile>
|
||||||
|
</TileGroup>
|
|
@ -34,3 +34,17 @@ components: ["SelectableTile"]
|
||||||
Multi-select Tile
|
Multi-select Tile
|
||||||
</SelectableTile>
|
</SelectableTile>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
### Disabled state
|
||||||
|
|
||||||
|
<div role="group" aria-label="selectable tiles">
|
||||||
|
<SelectableTile selected>
|
||||||
|
Multi-select Tile
|
||||||
|
</SelectableTile>
|
||||||
|
<SelectableTile disabled>
|
||||||
|
Multi-select Tile
|
||||||
|
</SelectableTile>
|
||||||
|
<SelectableTile disabled>
|
||||||
|
Multi-select Tile
|
||||||
|
</SelectableTile>
|
||||||
|
</div>
|
|
@ -5,6 +5,9 @@
|
||||||
/** Set to `true` to enable the light variant */
|
/** Set to `true` to enable the light variant */
|
||||||
export let light = false;
|
export let light = false;
|
||||||
|
|
||||||
|
/** Set to `true` to disable the tile */
|
||||||
|
export let disabled = false;
|
||||||
|
|
||||||
/** Specify the value of the radio input */
|
/** Specify the value of the radio input */
|
||||||
export let value = "";
|
export let value = "";
|
||||||
|
|
||||||
|
@ -21,7 +24,7 @@
|
||||||
export let name = "";
|
export let name = "";
|
||||||
|
|
||||||
import { getContext } from "svelte";
|
import { getContext } from "svelte";
|
||||||
import CheckmarkFilled16 from "carbon-icons-svelte/lib/CheckmarkFilled16";
|
import CheckmarkFilled16 from "carbon-icons-svelte/lib/CheckmarkFilled16/CheckmarkFilled16.svelte";
|
||||||
|
|
||||||
const { add, update, selectedValue } = getContext("TileGroup");
|
const { add, update, selectedValue } = getContext("TileGroup");
|
||||||
|
|
||||||
|
@ -36,14 +39,17 @@
|
||||||
name="{name}"
|
name="{name}"
|
||||||
value="{value}"
|
value="{value}"
|
||||||
checked="{checked}"
|
checked="{checked}"
|
||||||
tabindex="{tabindex}"
|
tabindex="{disabled ? undefined : tabindex}"
|
||||||
|
disabled="{disabled}"
|
||||||
class:bx--tile-input="{true}"
|
class:bx--tile-input="{true}"
|
||||||
on:change
|
on:change
|
||||||
on:change="{() => {
|
on:change="{() => {
|
||||||
|
if (disabled) return;
|
||||||
update(value);
|
update(value);
|
||||||
}}"
|
}}"
|
||||||
on:keydown
|
on:keydown
|
||||||
on:keydown="{(e) => {
|
on:keydown="{(e) => {
|
||||||
|
if (disabled) return;
|
||||||
if (e.key === ' ' || e.key === 'Enter') {
|
if (e.key === ' ' || e.key === 'Enter') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
update(value);
|
update(value);
|
||||||
|
@ -56,6 +62,7 @@
|
||||||
class:bx--tile--selectable="{true}"
|
class:bx--tile--selectable="{true}"
|
||||||
class:bx--tile--is-selected="{checked}"
|
class:bx--tile--is-selected="{checked}"
|
||||||
class:bx--tile--light="{light}"
|
class:bx--tile--light="{light}"
|
||||||
|
class:bx--tile--disabled="{disabled}"
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
on:click
|
on:click
|
||||||
on:mouseover
|
on:mouseover
|
||||||
|
|
|
@ -5,6 +5,9 @@
|
||||||
/** Set to `true` to enable the light variant */
|
/** Set to `true` to enable the light variant */
|
||||||
export let light = false;
|
export let light = false;
|
||||||
|
|
||||||
|
/** Set to `true` to disable the tile */
|
||||||
|
export let disabled = false;
|
||||||
|
|
||||||
/** Specify the title of the selectable tile */
|
/** Specify the title of the selectable tile */
|
||||||
export let title = "title";
|
export let title = "title";
|
||||||
|
|
||||||
|
@ -30,11 +33,11 @@
|
||||||
export let ref = null;
|
export let ref = null;
|
||||||
|
|
||||||
import { createEventDispatcher } from "svelte";
|
import { createEventDispatcher } from "svelte";
|
||||||
import CheckmarkFilled16 from "carbon-icons-svelte/lib/CheckmarkFilled16";
|
import CheckmarkFilled16 from "carbon-icons-svelte/lib/CheckmarkFilled16/CheckmarkFilled16.svelte";
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
$: dispatch(selected ? "select" : "deselect", id);
|
$: if (!disabled) dispatch(selected ? "select" : "deselect", id);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
|
@ -47,17 +50,20 @@
|
||||||
value="{value}"
|
value="{value}"
|
||||||
name="{name}"
|
name="{name}"
|
||||||
title="{title}"
|
title="{title}"
|
||||||
|
disabled="{disabled}"
|
||||||
/>
|
/>
|
||||||
<label
|
<label
|
||||||
for="{id}"
|
for="{id}"
|
||||||
tabindex="{tabindex}"
|
tabindex="{disabled ? undefined : tabindex}"
|
||||||
class:bx--tile="{true}"
|
class:bx--tile="{true}"
|
||||||
class:bx--tile--selectable="{true}"
|
class:bx--tile--selectable="{true}"
|
||||||
class:bx--tile--is-selected="{selected}"
|
class:bx--tile--is-selected="{selected}"
|
||||||
class:bx--tile--light="{light}"
|
class:bx--tile--light="{light}"
|
||||||
|
class:bx--tile--disabled="{disabled}"
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
on:click
|
on:click
|
||||||
on:click|preventDefault="{() => {
|
on:click|preventDefault="{() => {
|
||||||
|
if (disabled) return;
|
||||||
selected = !selected;
|
selected = !selected;
|
||||||
}}"
|
}}"
|
||||||
on:mouseover
|
on:mouseover
|
||||||
|
@ -65,6 +71,7 @@
|
||||||
on:mouseleave
|
on:mouseleave
|
||||||
on:keydown
|
on:keydown
|
||||||
on:keydown="{(e) => {
|
on:keydown="{(e) => {
|
||||||
|
if (disabled) return;
|
||||||
if (e.key === ' ' || e.key === 'Enter') {
|
if (e.key === ' ' || e.key === 'Enter') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
selected = !selected;
|
selected = !selected;
|
||||||
|
|
6
types/Tile/RadioTile.d.ts
vendored
6
types/Tile/RadioTile.d.ts
vendored
|
@ -15,6 +15,12 @@ export interface RadioTileProps
|
||||||
*/
|
*/
|
||||||
light?: boolean;
|
light?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to `true` to disable the tile
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
disabled?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify the value of the radio input
|
* Specify the value of the radio input
|
||||||
* @default ""
|
* @default ""
|
||||||
|
|
6
types/Tile/SelectableTile.d.ts
vendored
6
types/Tile/SelectableTile.d.ts
vendored
|
@ -15,6 +15,12 @@ export interface SelectableTileProps
|
||||||
*/
|
*/
|
||||||
light?: boolean;
|
light?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to `true` to disable the tile
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
disabled?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify the title of the selectable tile
|
* Specify the title of the selectable tile
|
||||||
* @default "title"
|
* @default "title"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue