From 06e0f36dda1457716e90716d1230d391b5e3620d Mon Sep 17 00:00:00 2001 From: Zak Burke Date: Thu, 9 Jul 2020 22:47:34 -0400 Subject: [PATCH] STCOM-715 Correct validation for User Record Custom Fields MultiSelection (#1328) Correctly present validation error for `` component if it has no value and disable `Save&Close` button Refs STCOM-715 Co-authored-by: Denys Bohdan --- lib/MultiSelection/MultiSelect.css | 12 +++++- lib/MultiSelection/MultiSelectFilterField.js | 2 +- lib/MultiSelection/MultiSelectValueInput.js | 40 +++++++++++++++++++ lib/MultiSelection/MultiSelection.js | 14 +++++++ .../tests/MultiSelection-test.js | 12 ++++++ lib/MultiSelection/tests/interactor.js | 9 +++-- 6 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 lib/MultiSelection/MultiSelectValueInput.js diff --git a/lib/MultiSelection/MultiSelect.css b/lib/MultiSelection/MultiSelect.css index a92f1856a..dc2f56d40 100644 --- a/lib/MultiSelection/MultiSelect.css +++ b/lib/MultiSelection/MultiSelect.css @@ -37,7 +37,7 @@ cursor: pointer; } -.multiSelectInput { +.multiSelectFilterField { margin: 2px; background-color: transparent; padding: 0 4px; @@ -45,6 +45,16 @@ outline: 0; } +.multiSelectValueInput { + position: absolute; + top: 0; + width: 100%; + height: 100%; + border: none; + z-index: -1; + color: transparent; +} + .multiSelectValueListContainer { display: flex; flex: 0 1 auto; diff --git a/lib/MultiSelection/MultiSelectFilterField.js b/lib/MultiSelection/MultiSelectFilterField.js index 32c7b6936..ccc576f17 100644 --- a/lib/MultiSelection/MultiSelectFilterField.js +++ b/lib/MultiSelection/MultiSelectFilterField.js @@ -71,7 +71,7 @@ class MultiSelectFilterField extends React.Component { onFocus, onBlur, placeholder, - 'className': css.multiSelectInput, + 'className': css.multiSelectFilterField, disabled, })} /> diff --git a/lib/MultiSelection/MultiSelectValueInput.js b/lib/MultiSelection/MultiSelectValueInput.js new file mode 100644 index 000000000..ffc487eb5 --- /dev/null +++ b/lib/MultiSelection/MultiSelectValueInput.js @@ -0,0 +1,40 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import css from './MultiSelect.css'; + +const propTypes = { + ariaLabelledBy: PropTypes.string, + getInputProps: PropTypes.func.isRequired, + id: PropTypes.string.isRequired, + required: PropTypes.bool, + value: PropTypes.string, +}; + +const MultiSelectValueInput = ({ + ariaLabelledBy, + id, + required, + getInputProps, + value, + ...rest +}) => ( + +); + +MultiSelectValueInput.propTypes = propTypes; + +MultiSelectValueInput.defaultProps = { + required: false, +}; + +export default MultiSelectValueInput; diff --git a/lib/MultiSelection/MultiSelection.js b/lib/MultiSelection/MultiSelection.js index c320f9f6f..e1fab3c02 100644 --- a/lib/MultiSelection/MultiSelection.js +++ b/lib/MultiSelection/MultiSelection.js @@ -15,6 +15,7 @@ import { FormattedMessage } from 'react-intl'; import MultiDownshift from './MultiDownshift'; import SelectedValuesList from './SelectedValuesList'; import MultiSelectFilterField from './MultiSelectFilterField'; +import MultiSelectValueInput from './MultiSelectValueInput'; import MultiSelectResponsiveRenderer from './MultiSelectResponsiveRenderer'; import SRStatus from '../SRStatus'; import DefaultOptionFormatter from '../Selection/DefaultOptionFormatter'; @@ -251,6 +252,10 @@ class MultiSelection extends React.Component { } }; + renderValueInput = (inputProps) => { + return ; + }; + handleDownshiftStateChange = (changes) => { if (this.props.asyncFiltering) { if (Object.prototype.hasOwnProperty.call(changes, 'isOpen') && @@ -384,6 +389,14 @@ class MultiSelection extends React.Component { disabled, }; + const inputProps = { + ariaLabelledBy, + id: `multiselect-input-${uiId}`, + required, + getInputProps, + value: Array.isArray(value) ? value.map(this.props.itemToString).join(',') : value, + }; + const optionListProps = { actions, ariaLabelledBy, @@ -465,6 +478,7 @@ class MultiSelection extends React.Component {
{this.renderInputOrPlaceholder(filterProps)} + {this.renderValueInput(inputProps)}