Skip to content

Commit 91b6c05

Browse files
feat(tile): add support for disabled state for radio and selectable tiles (#8058)
* feat(selectable-tile): add support for disabled state * feat(radio-tile): add support for disabled state * fix(tile): use disabled-02 for disabled outline and checkmark Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 9d5ddba commit 91b6c05

File tree

7 files changed

+67
-11
lines changed

7 files changed

+67
-11
lines changed

packages/components/src/components/tile/_tile.scss

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,7 @@
187187
opacity: 1;
188188
}
189189

190-
.#{$prefix}--tile-input:checked
191-
+ .#{$prefix}--tile
192-
> .#{$prefix}--tile__checkmark
193-
svg {
190+
.#{$prefix}--tile--is-selected .#{$prefix}--tile__checkmark svg {
194191
fill: $ui-05;
195192

196193
// Windows, Firefox HCM Fix
@@ -213,6 +210,26 @@
213210
.#{$prefix}--tile-input:focus + .#{$prefix}--tile {
214211
@include focus-outline('outline');
215212
}
213+
214+
.#{$prefix}--tile--disabled.#{$prefix}--tile--selectable {
215+
color: $disabled-02;
216+
background-color: $ui-01;
217+
cursor: not-allowed;
218+
}
219+
220+
.#{$prefix}--tile--disabled.#{$prefix}--tile--selectable.#{$prefix}--tile--light {
221+
background-color: $ui-02;
222+
}
223+
224+
.#{$prefix}--tile--disabled.#{$prefix}--tile--is-selected {
225+
outline-color: $disabled-02;
226+
}
227+
228+
.#{$prefix}--tile--disabled.#{$prefix}--tile--is-selected
229+
.#{$prefix}--tile__checkmark
230+
svg {
231+
fill: $disabled-02;
232+
}
216233
}
217234

218235
@include exports('tile') {

packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5740,6 +5740,9 @@ Map {
57405740
"className": Object {
57415741
"type": "string",
57425742
},
5743+
"disabled": Object {
5744+
"type": "bool",
5745+
},
57435746
"handleClick": Object {
57445747
"type": "func",
57455748
},
@@ -5868,6 +5871,9 @@ Map {
58685871
"defaultChecked": Object {
58695872
"type": "bool",
58705873
},
5874+
"disabled": Object {
5875+
"type": "bool",
5876+
},
58715877
"iconDescription": [Function],
58725878
"id": Object {
58735879
"type": "string",

packages/react/src/components/RadioTile/RadioTile-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,13 @@ describe('RadioButton', () => {
145145
expect(call[2].target).toBe(inputElement);
146146
});
147147
});
148+
149+
it('supports disabled state', () => {
150+
const wrapper = render({
151+
disabled: true,
152+
});
153+
154+
const input = () => wrapper.find('input');
155+
expect(input().props().disabled).toEqual(true);
156+
});
148157
});

packages/react/src/components/RadioTile/RadioTile.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const { prefix } = settings;
1919
function RadioTile({
2020
children,
2121
className,
22+
disabled,
2223
// eslint-disable-next-line no-unused-vars
2324
iconDescription,
2425
light,
@@ -38,6 +39,7 @@ function RadioTile({
3839
{
3940
[`${prefix}--tile--is-selected`]: checked,
4041
[`${prefix}--tile--light`]: light,
42+
[`${prefix}--tile--disabled`]: disabled,
4143
}
4244
);
4345

@@ -58,12 +60,13 @@ function RadioTile({
5860
{...other}
5961
type="radio"
6062
checked={checked}
63+
disabled={disabled}
6164
name={name}
6265
value={value}
6366
className={`${prefix}--tile-input`}
64-
tabIndex={tabIndex}
65-
onChange={handleOnChange}
66-
onKeyDown={handleOnKeyDown}
67+
tabIndex={!disabled ? tabIndex : null}
68+
onChange={!disabled ? handleOnChange : null}
69+
onKeyDown={!disabled ? handleOnKeyDown : null}
6770
id={inputId}
6871
/>
6972
<label htmlFor={inputId} className={classes}>
@@ -97,6 +100,11 @@ RadioTile.propTypes = {
97100
*/
98101
defaultChecked: PropTypes.bool,
99102

103+
/**
104+
* Specify whether the RadioTile should be disabled
105+
*/
106+
disabled: PropTypes.bool,
107+
100108
/**
101109
* The description of the tile checkmark icon.
102110
*/

packages/react/src/components/Tile/Tile-story.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const props = {
4747
handleClick: action('handleClick'),
4848
handleKeyDown: action('handleKeyDown'),
4949
light: boolean('Light variant (light)', false),
50+
disabled: boolean('Disabled (disabled)', false),
5051
}),
5152
group: () => ({
5253
name: text('Form item (name in <TileGroup>)', 'tile-group'),
@@ -61,6 +62,7 @@ const props = {
6162
name: text('Form item name (name in <RadioTile>)', 'tiles'),
6263
onChange: action('onChange'),
6364
light: boolean('Light variant (light)', false),
65+
disabled: boolean('Disabled (disabled)', false),
6466
}),
6567
expandable: () => ({
6668
tabIndex: number('Tab index (tabIndex)', 0),

packages/react/src/components/Tile/Tile-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ describe('Tile', () => {
220220
content.simulate('click');
221221
expect(onChange).toHaveBeenCalledTimes(2);
222222
});
223+
224+
it('supports disabled state', () => {
225+
wrapper.setProps({ disabled: true });
226+
expect(wrapper.find('input').props().disabled).toEqual(true);
227+
});
223228
});
224229

225230
describe('Renders expandable tile as expected', () => {

packages/react/src/components/Tile/Tile.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ export class SelectableTile extends Component {
197197
*/
198198
className: PropTypes.string,
199199

200+
/**
201+
* Specify whether the SelectableTile should be disabled
202+
*/
203+
disabled: PropTypes.bool,
204+
200205
/**
201206
* Specify the function to run when the SelectableTile is clicked
202207
*/
@@ -332,6 +337,7 @@ export class SelectableTile extends Component {
332337
// eslint-disable-next-line no-unused-vars
333338
onChange,
334339
light,
340+
disabled,
335341
...other
336342
} = this.props;
337343

@@ -341,6 +347,7 @@ export class SelectableTile extends Component {
341347
{
342348
[`${prefix}--tile--is-selected`]: this.state.selected,
343349
[`${prefix}--tile--light`]: light,
350+
[`${prefix}--tile--disabled`]: disabled,
344351
},
345352
className
346353
);
@@ -355,8 +362,9 @@ export class SelectableTile extends Component {
355362
id={id}
356363
className={`${prefix}--tile-input`}
357364
value={value}
358-
onChange={this.handleOnChange}
365+
onChange={!disabled ? this.handleOnChange : null}
359366
type="checkbox"
367+
disabled={disabled}
360368
name={name}
361369
title={title}
362370
checked={this.state.selected}
@@ -365,10 +373,11 @@ export class SelectableTile extends Component {
365373
<label
366374
htmlFor={id}
367375
className={classes}
368-
tabIndex={tabIndex}
376+
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
377+
tabIndex={!disabled ? tabIndex : null}
369378
{...other}
370-
onClick={this.handleClick}
371-
onKeyDown={this.handleKeyDown}>
379+
onClick={!disabled ? this.handleClick : null}
380+
onKeyDown={!disabled ? this.handleKeyDown : null}>
372381
<span className={`${prefix}--tile__checkmark`}>
373382
<CheckmarkFilled />
374383
</span>

0 commit comments

Comments
 (0)