Skip to content

Commit e45113b

Browse files
glsdowntcbegley
andauthored
Add form feedback support to Select (#755)
* Add select feedback * Add test Co-authored-by: tcbegley <tomcbegley@gmail.com>
1 parent 480ef7c commit e45113b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/components/input/Select.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ import RBFormSelect from 'react-bootstrap/FormSelect';
88
* list of dictionaries with keys label, value and disabled.
99
*/
1010
const Select = props => {
11-
const {className, class_name, html_size, ...otherProps} = props;
11+
const {
12+
className,
13+
class_name,
14+
html_size,
15+
valid,
16+
invalid,
17+
...otherProps
18+
} = props;
1219

1320
const handleChange = e => {
1421
if (props.setProps) {
@@ -29,6 +36,8 @@ const Select = props => {
2936
],
3037
otherProps
3138
)}
39+
isInvalid={invalid}
40+
isValid={valid}
3241
onChange={handleChange}
3342
className={class_name || className}
3443
htmlSize={html_size}

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

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

46+
test('sets validity using "valid" and "invalid" props', () => {
47+
const validSelect = render(<Select valid />);
48+
const invalidSelect = render(<Select invalid />);
49+
50+
expect(validSelect.container.firstChild).toHaveClass('is-valid');
51+
expect(invalidSelect.container.firstChild).toHaveClass('is-invalid');
52+
});
53+
4654
test('dispatches value when selection is made and setProps is set', () => {
4755
const mockSetProps = jest.fn();
4856
const {

0 commit comments

Comments
 (0)