Skip to content

Feat/indication for mandatory field #2775

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

Merged
merged 18 commits into from
Oct 29, 2023

Conversation

nitzanyiz
Copy link
Collaborator

Description

Added mandatory indication to the text field. The star (*) symbol is rendered conditionally if the textfield is required, i.e. has a required validator and showMandatoryIndication prop is present.

Changelog

TextField - Supports a mandatory star indication. A red star indication will show if the the TextField is required and showMandatoryIndication props is passed.

Additional info

Issue:
#2770

@nitzanyiz nitzanyiz marked this pull request as ready for review October 22, 2023 09:39
@nitzanyiz nitzanyiz requested a review from ethanshar October 22, 2023 09:39
@@ -162,13 +162,15 @@ export interface InputProps
*/
readonly?: boolean;
}
type MandatoryField = {showMandatoryIndication?: boolean}
Copy link
Collaborator

Choose a reason for hiding this comment

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

since this type contain a single property you might as well add it to the main TextFieldProp list directly

Comment on lines 140 to 142
const textFieldIsRequired =
(typeof others.validate === 'string' && others.validate === 'required') ||
(Array.isArray(others.validate) && others.validate.includes('required'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's move this part of logic to the hook that responsible for the field state (useFieldState)
You can add isMandatory to the fieldState object

<FieldContext.Provider value={context}>
<View {...containerProps} style={[margins, positionStyle, containerStyle, centeredContainerStyle]}>
let textFieldLabel = (
<Label
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of handling this logic in the main index, move it inside the Label component, so it's more encapsulated and less messy for the index file.

Moreover, consider not rendering two labels, but concatenate the * with the original label
I would not color the * with red, today we already have a solution for this in private (in TextField.config) where we don't color the * so better keep it aligned with our UI guidelines.

If you still want to support coloring the asterisk for the community (was it even requested by the user?) there are a bit simpler ways doing that..

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done. I had to pass the showMandatoryIndication to the label though.
On regard to the red asterisk there was an image attached to the issue where the asterisk was red so I thought this is what we wanted. I removed the coloring for now.

@nitzanyiz
Copy link
Collaborator Author

I moved the isMandatory to the useForm hook and the adding of the asterisk and the adding of the asterisk in the label component like we talked.
I added some tests as well - More for practice but they passed.

@nitzanyiz nitzanyiz requested a review from ethanshar October 26, 2023 10:37
@nitzanyiz nitzanyiz force-pushed the feat/indication-for-mandatory-field branch from b560298 to 2668879 Compare October 26, 2023 12:04
Copy link
Collaborator

@ethanshar ethanshar left a comment

Choose a reason for hiding this comment

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

Wrote small comment on a typo
Anyway approved. Merge after fixing the type

@@ -28,6 +28,7 @@ const Label = ({
const style = useMemo(() => {
return [styles.label, labelStyle, floatingPlaceholder && styles.dummyPlaceholder];
}, [labelStyle, floatingPlaceholder]);
const shouldRenderIdication = context.isMandatory && showMandatoryIndication;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Notice you have a typo here (shouldRenderIdication -> shouldRenderIndication)
Best way to spot typos is to install VSCode extension Code Spell Checker

@nitzanyiz nitzanyiz merged commit 40879e5 into master Oct 29, 2023
@ethanshar ethanshar deleted the feat/indication-for-mandatory-field branch October 30, 2023 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants