Skip to content

Commit e5d123e

Browse files
committed
feat(tile): support disabled state for SelectableTile, RadioTile
Closes #539
1 parent 50b93c8 commit e5d123e

File tree

8 files changed

+81
-5
lines changed

8 files changed

+81
-5
lines changed

COMPONENT_INDEX.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2946,6 +2946,7 @@ None.
29462946
| :-------------- | :--------------- | :------- | :------------------- | ------------------------------------------------ | -------------------------------------------------------- |
29472947
| checked | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to check the tile |
29482948
| light | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to enable the light variant |
2949+
| disabled | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to disable the tile |
29492950
| value | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the value of the radio input |
29502951
| tabindex | <code>let</code> | No | <code>string</code> | <code>"0"</code> | Specify the tabindex |
29512952
| 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.
31593160
| ref | <code>let</code> | Yes | <code>null &#124; HTMLInputElement</code> | <code>null</code> | Obtain a reference to the input HTML element |
31603161
| selected | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to select the tile |
31613162
| light | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to enable the light variant |
3163+
| disabled | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to disable the tile |
31623164
| title | <code>let</code> | No | <code>string</code> | <code>"title"</code> | Specify the title of the selectable tile |
31633165
| value | <code>let</code> | No | <code>string</code> | <code>"value"</code> | Specify the value of the selectable tile |
31643166
| tabindex | <code>let</code> | No | <code>string</code> | <code>"0"</code> | Specify the tabindex |

docs/src/COMPONENT_API.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7523,6 +7523,16 @@
75237523
"constant": false,
75247524
"reactive": false
75257525
},
7526+
{
7527+
"name": "disabled",
7528+
"kind": "let",
7529+
"description": "Set to `true` to disable the tile",
7530+
"type": "boolean",
7531+
"value": "false",
7532+
"isFunction": false,
7533+
"constant": false,
7534+
"reactive": false
7535+
},
75267536
{
75277537
"name": "value",
75287538
"kind": "let",
@@ -8176,6 +8186,16 @@
81768186
"constant": false,
81778187
"reactive": false
81788188
},
8189+
{
8190+
"name": "disabled",
8191+
"kind": "let",
8192+
"description": "Set to `true` to disable the tile",
8193+
"type": "boolean",
8194+
"value": "false",
8195+
"isFunction": false,
8196+
"constant": false,
8197+
"reactive": false
8198+
},
81798199
{
81808200
"name": "title",
81818201
"kind": "let",

docs/src/pages/components/RadioTile.svx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,18 @@ components: ["TileGroup", "RadioTile"]
3333
<RadioTile light value="2">
3434
Plus plan
3535
</RadioTile>
36+
</TileGroup>
37+
38+
### Disabled state
39+
40+
<TileGroup legend="Service pricing tiers">
41+
<RadioTile value="0" checked>
42+
Lite plan
43+
</RadioTile>
44+
<RadioTile value="1" disabled>
45+
Standard plan
46+
</RadioTile>
47+
<RadioTile value="2" disabled>
48+
Plus plan
49+
</RadioTile>
3650
</TileGroup>

docs/src/pages/components/SelectableTile.svx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,18 @@ components: ["SelectableTile"]
3333
<SelectableTile light>
3434
Multi-select Tile
3535
</SelectableTile>
36+
</div>
37+
38+
### Disabled state
39+
40+
<div role="group" aria-label="selectable tiles">
41+
<SelectableTile selected>
42+
Multi-select Tile
43+
</SelectableTile>
44+
<SelectableTile disabled>
45+
Multi-select Tile
46+
</SelectableTile>
47+
<SelectableTile disabled>
48+
Multi-select Tile
49+
</SelectableTile>
3650
</div>

src/Tile/RadioTile.svelte

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
/** Set to `true` to enable the light variant */
66
export let light = false;
77
8+
/** Set to `true` to disable the tile */
9+
export let disabled = false;
10+
811
/** Specify the value of the radio input */
912
export let value = "";
1013
@@ -21,7 +24,7 @@
2124
export let name = "";
2225
2326
import { getContext } from "svelte";
24-
import CheckmarkFilled16 from "carbon-icons-svelte/lib/CheckmarkFilled16";
27+
import CheckmarkFilled16 from "carbon-icons-svelte/lib/CheckmarkFilled16/CheckmarkFilled16.svelte";
2528
2629
const { add, update, selectedValue } = getContext("TileGroup");
2730
@@ -36,14 +39,17 @@
3639
name="{name}"
3740
value="{value}"
3841
checked="{checked}"
39-
tabindex="{tabindex}"
42+
tabindex="{disabled ? undefined : tabindex}"
43+
disabled="{disabled}"
4044
class:bx--tile-input="{true}"
4145
on:change
4246
on:change="{() => {
47+
if (disabled) return;
4348
update(value);
4449
}}"
4550
on:keydown
4651
on:keydown="{(e) => {
52+
if (disabled) return;
4753
if (e.key === ' ' || e.key === 'Enter') {
4854
e.preventDefault();
4955
update(value);
@@ -56,6 +62,7 @@
5662
class:bx--tile--selectable="{true}"
5763
class:bx--tile--is-selected="{checked}"
5864
class:bx--tile--light="{light}"
65+
class:bx--tile--disabled="{disabled}"
5966
{...$$restProps}
6067
on:click
6168
on:mouseover

src/Tile/SelectableTile.svelte

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
/** Set to `true` to enable the light variant */
66
export let light = false;
77
8+
/** Set to `true` to disable the tile */
9+
export let disabled = false;
10+
811
/** Specify the title of the selectable tile */
912
export let title = "title";
1013
@@ -30,11 +33,11 @@
3033
export let ref = null;
3134
3235
import { createEventDispatcher } from "svelte";
33-
import CheckmarkFilled16 from "carbon-icons-svelte/lib/CheckmarkFilled16";
36+
import CheckmarkFilled16 from "carbon-icons-svelte/lib/CheckmarkFilled16/CheckmarkFilled16.svelte";
3437
3538
const dispatch = createEventDispatcher();
3639
37-
$: dispatch(selected ? "select" : "deselect", id);
40+
$: if (!disabled) dispatch(selected ? "select" : "deselect", id);
3841
</script>
3942

4043
<input
@@ -47,24 +50,28 @@
4750
value="{value}"
4851
name="{name}"
4952
title="{title}"
53+
disabled="{disabled}"
5054
/>
5155
<label
5256
for="{id}"
53-
tabindex="{tabindex}"
57+
tabindex="{disabled ? undefined : tabindex}"
5458
class:bx--tile="{true}"
5559
class:bx--tile--selectable="{true}"
5660
class:bx--tile--is-selected="{selected}"
5761
class:bx--tile--light="{light}"
62+
class:bx--tile--disabled="{disabled}"
5863
{...$$restProps}
5964
on:click
6065
on:click|preventDefault="{() => {
66+
if (disabled) return;
6167
selected = !selected;
6268
}}"
6369
on:mouseover
6470
on:mouseenter
6571
on:mouseleave
6672
on:keydown
6773
on:keydown="{(e) => {
74+
if (disabled) return;
6875
if (e.key === ' ' || e.key === 'Enter') {
6976
e.preventDefault();
7077
selected = !selected;

types/Tile/RadioTile.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ export interface RadioTileProps
1515
*/
1616
light?: boolean;
1717

18+
/**
19+
* Set to `true` to disable the tile
20+
* @default false
21+
*/
22+
disabled?: boolean;
23+
1824
/**
1925
* Specify the value of the radio input
2026
* @default ""

types/Tile/SelectableTile.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ export interface SelectableTileProps
1515
*/
1616
light?: boolean;
1717

18+
/**
19+
* Set to `true` to disable the tile
20+
* @default false
21+
*/
22+
disabled?: boolean;
23+
1824
/**
1925
* Specify the title of the selectable tile
2026
* @default "title"

0 commit comments

Comments
 (0)