Skip to content

Commit a803128

Browse files
sstrubbergvpicone
andauthored
chore(Tile): updated props for v11 (#9628)
* chore(tile): update props and tests * chore(tile): fixed the tests Co-authored-by: @tay1orjones * chore(ExpandableTile): updated props co-authored-by: @tay1orjones * chore(tile): updated public api test * fix(tile): remove storybook actions * chore(button): removed deprecation warning * chore(tile): updated public api test * fix(tile): removed compose handlers Co-authored-by: Vince Picone <vpicone@gmail.com>
1 parent b5c1f82 commit a803128

File tree

4 files changed

+77
-51
lines changed

4 files changed

+77
-51
lines changed

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6379,9 +6379,9 @@ Map {
63796379
"ClickableTile" => Object {
63806380
"defaultProps": Object {
63816381
"clicked": false,
6382-
"handleClick": [Function],
6383-
"handleKeyDown": [Function],
63846382
"light": false,
6383+
"onClick": [Function],
6384+
"onKeyDown": [Function],
63856385
},
63866386
"propTypes": Object {
63876387
"children": Object {
@@ -6390,18 +6390,20 @@ Map {
63906390
"className": Object {
63916391
"type": "string",
63926392
},
6393-
"handleClick": Object {
6394-
"type": "func",
6395-
},
6396-
"handleKeyDown": Object {
6397-
"type": "func",
6398-
},
6393+
"handleClick": [Function],
6394+
"handleKeyDown": [Function],
63996395
"href": Object {
64006396
"type": "string",
64016397
},
64026398
"light": Object {
64036399
"type": "bool",
64046400
},
6401+
"onClick": Object {
6402+
"type": "func",
6403+
},
6404+
"onKeyDown": Object {
6405+
"type": "func",
6406+
},
64056407
"rel": Object {
64066408
"type": "string",
64076409
},
@@ -6410,6 +6412,9 @@ Map {
64106412
"SelectableTile" => Object {
64116413
"defaultProps": Object {
64126414
"light": false,
6415+
"onChange": [Function],
6416+
"onClick": [Function],
6417+
"onKeyDown": [Function],
64136418
"selected": false,
64146419
"tabIndex": 0,
64156420
"title": "title",
@@ -6474,9 +6479,9 @@ Map {
64746479
"ExpandableTile" => Object {
64756480
"defaultProps": Object {
64766481
"expanded": false,
6477-
"handleClick": [Function],
64786482
"light": false,
64796483
"onBeforeClick": [Function],
6484+
"onClick": [Function],
64806485
"tabIndex": 0,
64816486
"tileCollapsedIconText": "Interact to expand Tile",
64826487
"tileExpandedIconText": "Interact to collapse Tile",
@@ -6493,9 +6498,7 @@ Map {
64936498
"expanded": Object {
64946499
"type": "bool",
64956500
},
6496-
"handleClick": Object {
6497-
"type": "func",
6498-
},
6501+
"handleClick": [Function],
64996502
"id": Object {
65006503
"type": "string",
65016504
},

packages/react/src/components/Button/Button.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ const Button = React.forwardRef(function Button(
220220
onMouseLeave: composeEventHandlers([onMouseLeave, handleMouseLeave]),
221221
onFocus: composeEventHandlers([onFocus, handleFocus]),
222222
onBlur: composeEventHandlers([onBlur, handleBlur]),
223-
onClick: composeEventHandlers([handleClick, onClick]),
223+
onClick: composeEventHandlers([onClick, handleClick]),
224224
...other,
225225
...commonProps,
226226
...otherProps,

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
import React from 'react';
9-
import { action } from '@storybook/addon-actions';
109
import './tile-story.scss';
1110

1211
import {
@@ -51,8 +50,6 @@ const props = {
5150
}),
5251
selectable: () => ({
5352
selected: boolean('Selected (selected)', false),
54-
handleClick: action('handleClick'),
55-
handleKeyDown: action('handleKeyDown'),
5653
light: boolean('Light variant (light)', false),
5754
disabled: boolean('Disabled (disabled)', false),
5855
}),
@@ -63,11 +60,9 @@ const props = {
6360
radioValues,
6461
''
6562
),
66-
onChange: action('onChange'),
6763
}),
6864
radio: () => ({
6965
name: text('Form item name (name in <RadioTile>)', 'tiles'),
70-
onChange: action('onChange'),
7166
light: boolean('Light variant (light)', false),
7267
disabled: boolean('Disabled (disabled)', false),
7368
}),
@@ -84,7 +79,6 @@ const props = {
8479
),
8580
tileCollapsedLabel: text('Collapsed icon text (tileCollapsedLabel)'),
8681
tileExpandedLabel: text('Collapsed icon text (tileExpandedLabel)'),
87-
handleClick: action('handleClick'),
8882
light: boolean('Light variant (light)', false),
8983
}),
9084
};

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

Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import React, { Component, useEffect, useRef, useState } from 'react';
99
import PropTypes from 'prop-types';
10-
import classNames from 'classnames';
10+
import cx from 'classnames';
1111
import { settings } from 'carbon-components';
1212
import Link from '../Link';
1313
import {
@@ -45,16 +45,16 @@ export class Tile extends Component {
4545
};
4646

4747
render() {
48-
const { children, className, light, ...other } = this.props;
49-
const tileClasses = classNames(
48+
const { children, className, light, ...rest } = this.props;
49+
const tileClasses = cx(
5050
`${prefix}--tile`,
5151
{
5252
[`${prefix}--tile--light`]: light,
5353
},
5454
className
5555
);
5656
return (
57-
<div className={tileClasses} {...other}>
57+
<div className={tileClasses} {...rest}>
5858
{children}
5959
</div>
6060
);
@@ -76,14 +76,20 @@ export class ClickableTile extends Component {
7676
className: PropTypes.string,
7777

7878
/**
79-
* Specify the function to run when the ClickableTile is clicked
79+
* Deprecated in v11. Use 'onClick' instead.
8080
*/
81-
handleClick: PropTypes.func,
81+
handleClick: deprecate(
82+
PropTypes.func,
83+
'The handleClick prop for ClickableTile has been deprecated in favor of onClick. It will be removed in the next major release.'
84+
),
8285

8386
/**
8487
* Specify the function to run when the ClickableTile is interacted with via a keyboard
8588
*/
86-
handleKeyDown: PropTypes.func,
89+
handleKeyDown: deprecate(
90+
PropTypes.func,
91+
'The handleKeyDown prop for ClickableTile has been deprecated in favor of onKeyDown. It will be removed in the next major release.'
92+
),
8793

8894
/**
8995
* The href for the link.
@@ -96,6 +102,16 @@ export class ClickableTile extends Component {
96102
*/
97103
light: PropTypes.bool,
98104

105+
/**
106+
* Specify the function to run when the ClickableTile is clicked
107+
*/
108+
onClick: PropTypes.func,
109+
110+
/**
111+
* Specify the function to run when the ClickableTile is interacted with via a keyboard
112+
*/
113+
onKeyDown: PropTypes.func,
114+
99115
/**
100116
* The rel property for the link.
101117
*/
@@ -104,8 +120,8 @@ export class ClickableTile extends Component {
104120

105121
static defaultProps = {
106122
clicked: false,
107-
handleClick: () => {},
108-
handleKeyDown: () => {},
123+
onClick: () => {},
124+
onKeyDown: () => {},
109125
light: false,
110126
};
111127

@@ -116,7 +132,8 @@ export class ClickableTile extends Component {
116132
clicked: !this.state.clicked,
117133
},
118134
() => {
119-
this.props.handleClick(evt);
135+
// TODO: Remove handleClick prop when handleClick is deprecated
136+
this.props.handleClick?.(evt) || this.props.onClick?.(evt);
120137
}
121138
);
122139
};
@@ -129,11 +146,13 @@ export class ClickableTile extends Component {
129146
clicked: !this.state.clicked,
130147
},
131148
() => {
132-
this.props.handleKeyDown(evt);
149+
// TODO: Remove handleKeyDown prop when handleKeyDown is deprecated
150+
this.props.handleKeyDown?.(evt) || this.props.onKeyDown(evt);
133151
}
134152
);
135153
} else {
136-
this.props.handleKeyDown(evt);
154+
// TODO: Remove handleKeyDown prop when handleKeyDown is deprecated
155+
this.props.handleKeyDown?.(evt) || this.props.onKeyDown(evt);
137156
}
138157
};
139158

@@ -155,12 +174,14 @@ export class ClickableTile extends Component {
155174
className,
156175
handleClick, // eslint-disable-line
157176
handleKeyDown, // eslint-disable-line
177+
onClick, // eslint-disable-line
178+
onKeyDown, // eslint-disable-line
158179
clicked, // eslint-disable-line
159180
light,
160-
...other
181+
...rest
161182
} = this.props;
162183

163-
const classes = classNames(
184+
const classes = cx(
164185
`${prefix}--tile`,
165186
`${prefix}--tile--clickable`,
166187
{
@@ -174,7 +195,7 @@ export class ClickableTile extends Component {
174195
<Link
175196
href={href}
176197
className={classes}
177-
{...other}
198+
{...rest}
178199
onClick={this.handleClick}
179200
onKeyDown={this.handleKeyDown}>
180201
{children}
@@ -187,7 +208,7 @@ export function SelectableTile(props) {
187208
const {
188209
children,
189210
id,
190-
tabIndex = 0,
211+
tabIndex,
191212
value,
192213
name,
193214
title,
@@ -196,24 +217,24 @@ export function SelectableTile(props) {
196217
className,
197218
handleClick,
198219
handleKeyDown,
199-
onClick = () => {},
200-
onChange = () => {},
201-
onKeyDown = () => {},
220+
onClick,
221+
onChange,
222+
onKeyDown,
202223
light,
203224
disabled,
204225
selected,
205-
...other
226+
...rest
206227
} = props;
207228

208229
// TODO: replace with onClick when handleClick prop is deprecated
209230
const clickHandler = handleClick || onClick;
210231

211-
// TODO: replace with onClick when handleClick prop is deprecated
232+
// TODO: replace with onKeyDown when handleKeyDown prop is deprecated
212233
const keyDownHandler = handleKeyDown || onKeyDown;
213234

214235
const [isSelected, setIsSelected] = useState(selected);
215236
const input = useRef(null);
216-
const classes = classNames(
237+
const classes = cx(
217238
`${prefix}--tile`,
218239
`${prefix}--tile--selectable`,
219240
{
@@ -223,7 +244,7 @@ export function SelectableTile(props) {
223244
},
224245
className
225246
);
226-
const inputClasses = classNames(`${prefix}--tile-input`, {
247+
const inputClasses = cx(`${prefix}--tile-input`, {
227248
[`${prefix}--tile-input--checked`]: isSelected,
228249
});
229250

@@ -277,7 +298,7 @@ export function SelectableTile(props) {
277298
className={classes}
278299
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
279300
tabIndex={!disabled ? tabIndex : null}
280-
{...other}
301+
{...rest}
281302
onClick={!disabled ? handleOnClick : null}
282303
onKeyDown={!disabled ? handleOnKeyDown : null}>
283304
<span
@@ -295,6 +316,9 @@ SelectableTile.defaultProps = {
295316
selected: false,
296317
tabIndex: 0,
297318
light: false,
319+
onClick: () => {},
320+
onChange: () => {},
321+
onKeyDown: () => {},
298322
};
299323
SelectableTile.propTypes = {
300324
/**
@@ -409,9 +433,12 @@ export class ExpandableTile extends Component {
409433
expanded: PropTypes.bool,
410434

411435
/**
412-
* Specify the function to run when the ExpandableTile is clicked
436+
* Deprecated in v11. Use 'onClick' instead.
413437
*/
414-
handleClick: PropTypes.func,
438+
handleClick: deprecate(
439+
PropTypes.func,
440+
'The handleClick prop for ClickableTile has been deprecated in favor of onClick. It will be removed in the next major release.'
441+
),
415442

416443
/**
417444
* An ID that can be provided to aria-labelledby
@@ -430,7 +457,8 @@ export class ExpandableTile extends Component {
430457
onBeforeClick: PropTypes.func,
431458

432459
/**
433-
* optional handler to trigger a function the Tile is clicked
460+
* Specify the function to run when the ExpandableTile is clicked
461+
434462
*/
435463
onClick: PropTypes.func,
436464

@@ -471,7 +499,7 @@ export class ExpandableTile extends Component {
471499
tileMaxHeight: 0,
472500
tilePadding: 0,
473501
onBeforeClick: () => true,
474-
handleClick: () => {},
502+
onClick: () => {},
475503
tileCollapsedIconText: 'Interact to expand Tile',
476504
tileExpandedIconText: 'Interact to collapse Tile',
477505
light: false,
@@ -549,7 +577,8 @@ export class ExpandableTile extends Component {
549577
},
550578
() => {
551579
this.setMaxHeight();
552-
this.props.handleClick(evt);
580+
// TODO: Remove handleClick prop when handleClick is deprecated
581+
this.props.handleClick?.(evt) || this.props.onClick?.(evt);
553582
}
554583
);
555584
};
@@ -582,12 +611,12 @@ export class ExpandableTile extends Component {
582611
tileExpandedLabel,
583612
onBeforeClick, // eslint-disable-line
584613
light,
585-
...other
614+
...rest
586615
} = this.props;
587616

588617
const { expanded: isExpanded } = this.state;
589618

590-
const classes = classNames(
619+
const classes = cx(
591620
`${prefix}--tile`,
592621
`${prefix}--tile--expandable`,
593622
{
@@ -616,7 +645,7 @@ export class ExpandableTile extends Component {
616645
className={classes}
617646
aria-expanded={isExpanded}
618647
title={isExpanded ? tileExpandedIconText : tileCollapsedIconText}
619-
{...other}
648+
{...rest}
620649
onKeyUp={composeEventHandlers([onKeyUp, this.handleKeyUp])}
621650
onClick={composeEventHandlers([onClick, this.handleClick])}
622651
tabIndex={tabIndex}>

0 commit comments

Comments
 (0)