Skip to content
New issue

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

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

Already on GitHub? # to your account

[enhancement] FormSelect #242

Closed
daniele-zurico opened this issue Oct 23, 2021 · 0 comments · Fixed by #257
Closed

[enhancement] FormSelect #242

daniele-zurico opened this issue Oct 23, 2021 · 0 comments · Fixed by #257
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@daniele-zurico
Copy link
Contributor

daniele-zurico commented Oct 23, 2021

We should simplify the usage of the formSelect component to allow the developer to use it easily.
### IMPORTANT: We don't need to remove or break any pre-existing functionality but we need to add extra properties.

  1. Currently when you want to pass the options you need to specify the value and the label.
options={[{
      label: 'Recently published',
      value: 'published'
    }]}

This is perfect in case I want a different label from the value but what about if I don't have this requirement and label is the same of value?

options={['a', 'b', 'c'] }

The component need to be smart and able to manage both scenarios.

  1. The current usage of classes is really verbose we should instead allow to do this:
<FormSelect 
    selectClassName="form-control"    <------
    errorContainerClassName="form-group-error"	<---- it has to be smart and add this class in case of error
    errorClassName="error-message"  <------- this will format the label error
    labelClassName="form-label"    <--------- this will format the label
    errorMessage={error}		<---- this will allow to pass a simple string
    label={label} 
    id={id} 
    name={name}
    value={value} 
    options={concatOptions} 
   onChange={onChange}
   nullOption="Select..."
/>

To obtain the same result currently I had to do the following:

<div className={['form-group', error ? 'form-group-error': null].join('')}>   
    <FormSelect 
         className="form-control" 
          label={label} 
          id={id} 
          name={name}
          value={value} 
          options={concatOptions} 
          error={{
            text: error,
            className: 'error-message',
          }} 
           onChange={onChange}
           nullOption="Select..."
           labelProps={{
            className: 'form-label',
          }}
     />
</div>
  1. I also tried to use it with a label and to have the label on top I had to wrap everything in another div:
<div className="m-3">
                <FormSelect
                  label="Basic"
                  options={(item as UserOptionalCustomisation).options}
                  onChange={handleValueChange}
                  labelProps={{
                    //@ts-ignore
                    className:
                      "block text-xs font-bold pb-1 text-gray-500 mr-4 flex items-end ml-0.5",
                  }}
                  className="text-xs p-1 border-gray-300 border rounded text-gray-500"
                />
              </div>
  1. For the pre-selected value I had to use it inside the options but it could be better if is specified outisde the options as another props:
options: [
      { label: "bottom", value: "bottom", selected: true },
      { label: "top", value: "top" },
    ]

Important: please use release/0.4 as base branch

@daniele-zurico daniele-zurico added the enhancement New feature or request label Oct 23, 2021
@daniele-zurico daniele-zurico added this to the 0.4 milestone Oct 23, 2021
@daniele-zurico daniele-zurico self-assigned this Jan 17, 2022
@daniele-zurico daniele-zurico linked a pull request Jan 31, 2022 that will close this issue
4 tasks
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant