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

Radio e Checkbox Groups #2030

Open
lafray opened this issue Oct 24, 2024 · 0 comments
Open

Radio e Checkbox Groups #2030

lafray opened this issue Oct 24, 2024 · 0 comments
Labels
proposal Proposals for enhancements to the software

Comments

@lafray
Copy link
Contributor

lafray commented Oct 24, 2024

Problem

Acredito que tenha uma questão de diferença entre o comportamento desses campos e os outros campos da lib (como Input, TextArea, etc.) que não deveria existir. Na evolução de admin-ui para shoreline, o elementos passaram a ser mais composible e no caso de elementos de formulário, foi criado o Field e seus subcomponentes para poder desvincular o label error message e etc do componente de input em sim. Porém isso não ocorreu com com o CheckboxGroup e RaidoGroup. Olhando o código eles internamente, eles utilizam so componente Field. Acredito que para uniformidade do comportamente dos componentes de formulário, ele não deveria instacializar eles esses elementos de Field, e que usar que deveria fazer isso externamente.

Solution

before

export const RadioGroup = forwardRef<HTMLInputElement, RadioGroupProps>(
  function Radio(props, ref) {
    const {
      error,
      description,
      errorText,
      label,
      children,
      className,
      horizontal = false,
      state,
      id: defaultId,
      ...otherProps
    } = props

    const id = useId(defaultId)

    return (
      <RadioProvider store={state}>
        <Field
          space="large"
          data-sl-radio-group
          error={error}
          className={className}
        >
          <Label htmlFor={id}>{label}</Label>
          <BaseRadioGroup data-sl-group id={id} ref={ref} {...otherProps}>
            <Stack
              horizontal={horizontal}
              space={horizontal ? '$space-5' : '$space-4'}
            >
              {children}
            </Stack>
          </BaseRadioGroup>
          {description && <FieldDescription>{description}</FieldDescription>}
          <FieldError>{errorText}</FieldError>
        </Field>
      </RadioProvider>
    )
  }
)

After

export const RadioGroup = forwardRef<HTMLInputElement, RadioGroupProps>(
  function Radio(props, ref) {
    const {
      error,
      description,
      errorText,
      label,
      children,
      className,
      horizontal = false,
      state,
      id: defaultId,
      ...otherProps
    } = props

    const store = useFieldContext()
    const { id: contextId } = useStore(store, (s) => s)
    const id = defaultId ?? contextId

    return (
      <RadioProvider store={state}>
          <BaseRadioGroup data-sl-group id={id} ref={ref} {...otherProps}>
            <Stack
              horizontal={horizontal}
              space={horizontal ? '$space-5' : '$space-4'}
            >
              {children}
            </Stack>
          </BaseRadioGroup>
      </RadioProvider>
    )
  }
)

Note

Aplicar o mesmo para o CheckboxGroup

Important

Entendo que é uma breakchange, então teria que fazer algo intermediario enquanto não for lançar uma nova major

Usage examples

before:

<RadioGroup label="Label" description="Short description">
      <Radio value="opt1">Pen</Radio>
      <Radio value="opt2">Pineapple</Radio>
      <Radio value="opt3">Apple</Radio>
      <Radio value="opt4">Another pen</Radio>
</RadioGroup>

after

<Field>
      <Label>Label</Label>
      <RadioGroup>
            <Radio value="opt1">Pen</Radio>
            <Radio value="opt2">Pineapple</Radio>
            <Radio value="opt3">Apple</Radio>
            <Radio value="opt4">Another pen</Radio>
      </RadioGroup>
      <FieldDescription>Short description</FieldDescription>
</Field>

That is more similare with Input use

<Field>
      <Label>Label</Label>
      <Input />
      <FieldDescription>Short description</FieldDescription>
</Field>

Dependencies

No response

References

@lafray lafray added the proposal Proposals for enhancements to the software label Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Proposals for enhancements to the software
Projects
Status: No status
Development

No branches or pull requests

1 participant