From b60ef7ebbe89d3a87dd2972eb4568003da26ecfd Mon Sep 17 00:00:00 2001 From: John Coburn Date: Fri, 28 Jun 2024 11:30:43 -0500 Subject: [PATCH] pass onBlur, onFocus handlers into selection and test form library functionality for Selection (#2308) --- lib/Selection/Selection.js | 11 +++++++ .../tests/Selection-ReduxForm-test.js | 33 ++++++++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/lib/Selection/Selection.js b/lib/Selection/Selection.js index 542792e32..f7d08d512 100644 --- a/lib/Selection/Selection.js +++ b/lib/Selection/Selection.js @@ -5,6 +5,7 @@ import { useCombobox } from 'downshift'; import classNames from 'classnames'; import isEqual from 'lodash/isEqual'; import formField from '../FormField'; +import parseMeta from '../FormField/parseMeta'; import { defaultItemToString, @@ -95,7 +96,9 @@ const Selection = ({ formatter = DefaultOptionFormatter, id, inputRef, + onBlur, onChange, + onFocus, placeholder, label, listMaxHeight = '174px', @@ -297,6 +300,8 @@ const Selection = ({ })} className={getControlClass} autoFocus={autofocus} + onBlur={onBlur} + onFocus={onFocus} > {formatMessage({ id: 'stripes-components.selection.controlLabel' })} {valueLabel} @@ -304,6 +309,10 @@ const Selection = ({
+
+ {warning &&
{warning}
} + {error &&
{error}
} +
{ describe('coupled to redux-form', () => { beforeEach(async () => { + const validate = () => 'there\'s a problem!' await mountWithContext( { name="testField" component={Selection} dataOptions={[ - { value: 'test', label: 'Hello World' } + { value: 'test', label: 'Hello World' }, + { value: 'test2', label: 'Hello World2' } ]} + validate={validate} /> + ); + await selection.focus(); }); - it('renders the control', () => { - selection.exists(); + it('renders the control', () => selection.exists()); + + it('focuses the button', () => Button({ focused: true }).exists()); + + describe('using the control', () => { + beforeEach(async () => { + await selection.choose('Hello World'); + }); + + it('sets the chosen label in the control field', () => selection.has({ value: 'Select controlHello World' })); + + describe('after using the control', () => { + beforeEach(async () => { + await TextInput().focus(); + }); + + it('displays redux-form validation', () => selection.has({ error: 'there\'s a problem!' })); + }); }); }); });