Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: No required field validation state picker #33926

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 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,18 @@ function StatePicker({value, errorText, onInputChange, forwardedRef, label}) {
setIsPickerVisible(true);
};

const hidePickerModal = () => {
const hidePickerModal = (isUpdateStateInput = false) => {
if (!isUpdateStateInput) {
onBlur();
}
Copy link
Contributor Author

@DylanDylann DylanDylann Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • There are a few methods that can make the picker modal hidden, for example, clicking on back button, or clicking on any option.
  • We only call the onBlur function if the modal is hidden when user clicks on the back button
  • If we call the onBlur function if the modal is hidden when user clicks on any option as well, and the user did not open the picker modal before, then opened it, and clicked on any option, the modal will be hidden and the error message appears for a while

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename isUpdateStateInput to shouldBur and default it to true , also let's add a comment explaining it.

DylanDylann marked this conversation as resolved.
Show resolved Hide resolved
setIsPickerVisible(false);
};

const updateStateInput = (state) => {
if (state.value !== value) {
onInputChange(state.value);
}
hidePickerModal();
hidePickerModal(true);
DylanDylann marked this conversation as resolved.
Show resolved Hide resolved
};

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