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

FormField components #2311

Closed
15 of 16 tasks
Tracked by #1045
mrosvik opened this issue Aug 22, 2024 · 2 comments
Closed
15 of 16 tasks
Tracked by #1045

FormField components #2311

mrosvik opened this issue Aug 22, 2024 · 2 comments
Labels
css @digdir/designsystemet-css ☂️ epic Issues ready react @digdir/designsystemet-react

Comments

@mrosvik
Copy link
Member

mrosvik commented Aug 22, 2024

Some designsystems use generic form classes/components, usually called form-group or form-field for their form components to have consistent placement of label, descriptions and such around an input/textarea/select element.

Notes:

This could be possible if we split up Textfield into multiple sub-components or generic form scaffolding components.

More generic, example from Radix:

  <Form.Root>
    <Form.Field>
      <Form.Label />
      <Form.Control asChild>
        <input className="Input" type="email" required />
      </Form.Control>
      <Form.Message />
      <Form.ValidityState />
    </Form.Field>

    <Form.Message />
    <Form.ValidityState />

    <Form.Submit />
  </Form.Root>

Or more scoped, Example from Ark UI

import { Field } from '@ark-ui/react'

export const Input = () => {
  return (
    <Field.Root>
      <Field.Label>Label</Field.Label>
      <Field.Input />
      <Field.HelperText>Some additional Info</Field.HelperText>
      <Field.ErrorText>Error Info</Field.ErrorText>
    </Field.Root>
  )
}

Tasks

Preview Give feedback
  1. react
    mimarz
  2. css react
    Barsnes
  3. react
    Barsnes
  4. react 🕵️ investigate
    eirikbacker
  5. css 🐛 bug
  6. react
    mimarz
  7. react
    eirikbacker
  8. react
    eirikbacker
  9. Barsnes
  10. eirikbacker
@mrosvik mrosvik converted this from a draft issue Aug 22, 2024
@mrosvik mrosvik added the 🕵️ investigate Needs investigation label Aug 22, 2024
@mimarz mimarz added react @digdir/designsystemet-react css @digdir/designsystemet-css labels Aug 22, 2024
@eirikbacker
Copy link
Contributor

eirikbacker commented Aug 23, 2024

This is a React specific issue. I would argue, that we should in general skip the .Root level, and just do for instance:

<Accordion>
  <Accordion.Heading></Accordion.Heading>
  <Accordion.Content></Accordion.Content>
</Accordion>

When the base component is rendering a actual HTML element, as this clean and a very common pattern:
https://www.patterns.dev/react/compound-pattern/

When using .Root (or .Provider), the common pattern is that this is an indication to the consumer that the React element does not render any HTML, but is there more to provide a functional context:
https://kyleshevlin.com/compound-components/
https://medium.com/@win.le/react-compound-component-with-typescript-d7944ac0d1d6

This separation makes it easier to resonate and exemplify about how our design system translates between React and HTML and other frameworks, as the functional useContext is mostly a React pattern.

That said, I think we can maybe flip the question, and ask;

  • Binding the label + helptext + input + error message is a somewhat repetitive wiring task. We could provide a optional utility for this, and this could both be exposed as a React component, but also also in time as maybe a custom element <ds-field>. If we want something like this as an end goal, does that change our implementation for React?

Could the interface then be something like:

<Field>
  <Label>Label</Label>
  <Input />
  <Field.Help>Some additional Info</Field.Help>
  <Field.Error>Error Info</Field.Error>
</Field.Root>

...where <Label> and <Input> is not prefixed - aligning with native elements and HTML standard, and indicating that Field is optional just like in pure HTML? Pure HTML-example of the same:

<ds-field>
  <label>Label</label>
  <input />
  <ds-field-help>Some additional Info</ds-field-help>
  <ds-field-error>Error Info</ds-field-error>
</ds-field>

(dropping form from the name as input-like elements does not actually require being placed inside a form).

@mrosvik mrosvik modified the milestones: V1, V1 - Helhetlig fargesystem, V1 - Helhetlig komponentbibliotek Aug 26, 2024
@mimarz mimarz changed the title Should our form components support Root pattern? Should our form components support context pattern? Sep 10, 2024
@mimarz mimarz changed the title Should our form components support context pattern? Should we have generic form components? Sep 12, 2024
@mimarz mimarz removed the 🕵️ investigate Needs investigation label Sep 19, 2024
@mimarz mimarz changed the title Should we have generic form components? Form compound components Sep 19, 2024
@mimarz mimarz added the ☂️ epic Issues ready label Sep 25, 2024
@mimarz mimarz changed the title Form compound components FormField components Sep 25, 2024
eirikbacker added a commit that referenced this issue Oct 11, 2024
- Resolves #2553
- Resolves #2587
- Part of #2311
- Make standalone `<Input>`
- Adds support for `type="radio"` and `type="checkbox"`
- Adds support for `role="switch"`
- Documentation for standalone components should be discussed with the
team (#2566) and not solved in this PR
- Some changes might occur later after #2561, but I suggest we merge
this first to be able to move forward
eirikbacker added a commit that referenced this issue Oct 11, 2024
- Adds `select` and `textarea` to #2550 
- Part of #2311
- Select chevron adjustments are verified by Lasse
eirikbacker added a commit that referenced this issue Oct 24, 2024
- Part of #2311
- Fieldset at compound components moved to task #2666 
- Fixes #2459
Barsnes added a commit that referenced this issue Oct 28, 2024
commit ce23f32
Author: Eirik Backer <eirik.backer@gmail.com>
Date:   Mon Oct 28 10:31:21 2024 +0100

    fix(Chip): use input component (#2683)

    - Fixes #2669
    - Fixes wrong height implemented (now correctly `32px`)
    - Implements simplified states after dialogue with Marianne
    - Fixes better alignment of label vs. radio/checkbox
    - Implements logic so elements with the `ds-focus--visible` class
    automatically hides focus ring on children (no need for confusing,
    nested focus rings)

commit d5e0ba1
Author: Lasse Febakke Straum <33222679+Febakke@users.noreply.github.com>
Date:   Fri Oct 25 15:08:14 2024 +0200

    refactor(tokens): changed spacing and sizing type to dimension (#2688)

    Co-authored-by: Tobias Barsnes <tobias.barsnes@digdir.no>
    Co-authored-by: Michael Marszalek <mimarz@gmail.com>

commit 6c1f99d
Author: Eirik Backer <eirik.backer@gmail.com>
Date:   Fri Oct 25 13:52:51 2024 +0200

    chore: remove tmp field styling in testing story (#2687)

    - Since field styling is now merged, `testing.stories.tsx` no longer
    needs to fake it

commit f4f76d3
Author: Eirik Backer <eirik.backer@gmail.com>
Date:   Fri Oct 25 13:41:36 2024 +0200

    fix(Heading+Label+ValidationMessage): clean up css styles (#2677)

    Figma task is added as #2676

commit d2fc6b9
Author: Tobias Barsnes <tobias.barsnes@digdir.no>
Date:   Fri Oct 25 13:16:17 2024 +0200

    feat: rename `size` prop to `data-size` (#2680)

    resolves #2673

commit acef771
Author: Eirik Backer <eirik.backer@gmail.com>
Date:   Fri Oct 25 10:24:19 2024 +0200

    fix(Input): inherit line-height (#2685)

    As pointed out by hawk-eye @mimarz 💪 🙏 🦅
    https://designsystemet.slack.com/archives/C07K7NEKXEW/p1729843841118129

commit d3c58b0
Author: Eirik Backer <eirik.backer@gmail.com>
Date:   Fri Oct 25 10:04:16 2024 +0200

    fix(Spinner): use forwardRef and aria-label for consistency (#2682)

    - Use `aria-label` for accessible spinner label to be consistent with
    other components
    - Use `forwardRef` on Spinner

    ---------

    Co-authored-by: Tobias Barsnes <tobias.barsnes@digdir.no>

commit 326671a
Author: Une Sofie Kinn Ekroll <une.kinn.ekroll@bekk.no>
Date:   Fri Oct 25 08:26:49 2024 +0200

    feat(tokens): add modes for semantic color categories main & support (#2643)

    Co-authored-by: Lasse Febakke Straum <33222679+Febakke@users.noreply.github.com>

commit 7520547
Author: Eirik Backer <eirik.backer@gmail.com>
Date:   Thu Oct 24 14:19:33 2024 +0200

    fix(Radio+Checkbox): use input component (#2607)

    - Part of #2311
    - Fieldset at compound components moved to task #2666
    - Fixes #2459

commit f96289a
Author: Tobias Barsnes <tobias.barsnes@digdir.no>
Date:   Thu Oct 24 11:17:42 2024 +0200

    chore: enable `noUnusedImports` biome rule (#2675)

    enables https://biomejs.dev/linter/rules/no-unused-imports/

commit a452813
Author: Une Sofie Kinn Ekroll <une.kinn.ekroll@bekk.no>
Date:   Thu Oct 24 10:38:59 2024 +0200

    feat(cli,theme): don't output underlying primitives for semantic color variables (#2641)
eirikbacker added a commit that referenced this issue Oct 31, 2024
Barsnes added a commit that referenced this issue Nov 5, 2024
part of #2311

New API:
```tsx
  <Search>
    <Search.Input aria-label='Søk' />
    <Search.Clear />
    <Search.Button /> /* can be removed to get a simple variant */
  </Search>
```

---------

Co-authored-by: Eirik Backer <eirik.backer@gmail.com>
@mimarz
Copy link
Collaborator

mimarz commented Dec 11, 2024

We have finished this, further tweaks and adjustments will be done in separate issues

@mimarz mimarz closed this as completed Dec 11, 2024
@github-project-automation github-project-automation bot moved this from ☂ Todo Epics to ✅ Done in Team Designsystemet Dec 11, 2024
@mrosvik mrosvik modified the milestones: Helhetlig komponentbibliotek, V1 - Lansering Jan 28, 2025
mimarz pushed a commit that referenced this issue Feb 21, 2025
- Resolves #2553
- Resolves #2587
- Part of #2311
- Make standalone `<Input>`
- Adds support for `type="radio"` and `type="checkbox"`
- Adds support for `role="switch"`
- Documentation for standalone components should be discussed with the
team (#2566) and not solved in this PR
- Some changes might occur later after #2561, but I suggest we merge
this first to be able to move forward
mimarz pushed a commit that referenced this issue Feb 21, 2025
- Adds `select` and `textarea` to #2550 
- Part of #2311
- Select chevron adjustments are verified by Lasse
mimarz pushed a commit that referenced this issue Feb 21, 2025
- Part of #2311
- Fieldset at compound components moved to task #2666 
- Fixes #2459
mimarz pushed a commit that referenced this issue Feb 21, 2025
mimarz pushed a commit that referenced this issue Feb 21, 2025
part of #2311

New API:
```tsx
  <Search>
    <Search.Input aria-label='Søk' />
    <Search.Clear />
    <Search.Button /> /* can be removed to get a simple variant */
  </Search>
```

---------

Co-authored-by: Eirik Backer <eirik.backer@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css @digdir/designsystemet-css ☂️ epic Issues ready react @digdir/designsystemet-react
Projects
Status: ✅ Done
Development

No branches or pull requests

3 participants