Skip to content

Commit 310ae02

Browse files
authored
Allow Select to be cleared with None (#842)
* Test None clears select * Clear Select with None
1 parent 9981371 commit 310ae02

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/components/input/Select.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const Select = props => {
1414
html_size,
1515
valid,
1616
invalid,
17+
value,
1718
...otherProps
1819
} = props;
1920

@@ -41,6 +42,7 @@ const Select = props => {
4142
onChange={handleChange}
4243
className={class_name || className}
4344
htmlSize={html_size}
45+
value={value || ''}
4446
>
4547
<option value="" disabled hidden>
4648
{props.placeholder}

src/components/input/__tests__/Select.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@ describe('Select', () => {
4343
expect(select).not.toHaveValue();
4444
});
4545

46+
test('null will clear value', () => {
47+
const {
48+
container: {firstChild: select}
49+
} = render(
50+
<Select
51+
id="test-select"
52+
options={[
53+
{label: 'Item 1', value: '1'},
54+
{label: 'Item 2', value: '2'}
55+
]}
56+
value={null}
57+
/>
58+
);
59+
60+
expect(select).not.toHaveValue();
61+
});
62+
4663
test('sets validity using "valid" and "invalid" props', () => {
4764
const validSelect = render(<Select valid />);
4865
const invalidSelect = render(<Select invalid />);

0 commit comments

Comments
 (0)