Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit afc16c8

Browse files
mgr34Matt Goo
authored and
Matt Goo
committed
fix(chips): id shuold be required prop (#649)
1 parent a646a33 commit afc16c8

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

packages/chips/ChipSet.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ export default class ChipSet extends React.Component<ChipSetProps, ChipSetState>
160160
};
161161

162162
renderChip = (chip: any) => {
163-
const {filter} = this.props;
163+
const {choice, filter, input} = this.props;
164+
if ((choice || filter || input) && !chip.props.id) {
165+
throw new Error('Chip variant missing required property: id.');
166+
}
167+
164168
const {selectedChipIds} = this.state;
165169
const selected = selectedChipIds.indexOf(chip.props.id) > -1;
166170
const {handleInteraction, handleSelect, handleRemove, ...chipProps} = chip.props;

test/unit/chips/ChipSet.test.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,31 @@ test('chip is rendered with computeBoundingRect method prop if is not filter var
420420
assert.equal(chip.props.computeBoundingRect, null);
421421
});
422422

423+
test('basic variant ChipSet will not throw error if chip missing id', () => {
424+
const stub = (<Chip/>);
425+
const wrapper = shallow<ChipSet>(<ChipSet/>);
426+
assert.doesNotThrow(() => wrapper.instance().renderChip(stub));
427+
});
428+
429+
430+
test('filter variant ChipSet will throw error if chip missing id', () => {
431+
const stub = (<Chip/>);
432+
const wrapper = shallow<ChipSet>(<ChipSet filter />);
433+
assert.throws(() => wrapper.instance().renderChip(stub));
434+
});
435+
436+
test('choice variant ChipSet will throw error if chip missing id', () => {
437+
const stub = (<Chip/>);
438+
const wrapper = shallow<ChipSet>(<ChipSet choice />);
439+
assert.throws(() => wrapper.instance().renderChip(stub));
440+
});
441+
442+
test('input variant of ChipSet will throw error if chip missing id', () => {
443+
const stub = (<Chip/>);
444+
const wrapper = shallow<ChipSet>(<ChipSet input />);
445+
assert.throws(() => wrapper.instance().renderChip(stub));
446+
});
447+
423448
test('#componentWillUnmount destroys foundation', () => {
424449
const wrapper = shallow<ChipSet>(<ChipSet><Chip id='1' /></ChipSet>);
425450
const foundation = wrapper.state().foundation;

0 commit comments

Comments
 (0)