Skip to content

Commit

Permalink
Merge pull request #33926 from DylanDylann/fix/30195
Browse files Browse the repository at this point in the history
Fix: No required field validation state picker
  • Loading branch information
nkuoch authored Jan 9, 2024
2 parents a4bdebe + cb544b7 commit 56d732b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/components/StatePicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const propTypes = {

/** Label to display on field */
label: PropTypes.string,

/** Callback to call when the picker modal is dismissed */
onBlur: PropTypes.func,
};

const defaultProps = {
Expand All @@ -33,9 +36,10 @@ const defaultProps = {
errorText: '',
onInputChange: () => {},
label: undefined,
onBlur: () => {},
};

function StatePicker({value, errorText, onInputChange, forwardedRef, label}) {
function StatePicker({value, errorText, onInputChange, forwardedRef, label, onBlur}) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const [isPickerVisible, setIsPickerVisible] = useState(false);
Expand All @@ -45,15 +49,20 @@ function StatePicker({value, errorText, onInputChange, forwardedRef, label}) {
setIsPickerVisible(true);
};

const hidePickerModal = () => {
const hidePickerModal = (shouldBlur = true) => {
if (shouldBlur) {
onBlur();
}
setIsPickerVisible(false);
};

const updateStateInput = (state) => {
if (state.value !== value) {
onInputChange(state.value);
}
hidePickerModal();
// If the user selects any state, call the hidePickerModal function with shouldBlur = false
// to prevent the onBlur function from being called.
hidePickerModal(false);
};

const title = value && _.keys(COMMON_CONST.STATES).includes(value) ? translate(`allStates.${value}.stateName`) : '';
Expand Down

0 comments on commit 56d732b

Please sign in to comment.