Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Checkbox with label is rendered wrong #929

Closed as not planned
Closed as not planned
@seriema

Description

@seriema

Issue

According to the readme it's possible to just add a standard <label> element after the checkbox.

        <Checkbox
          nativeControlId='my-checkbox'
          checked={this.state.checked}
          indeterminate={this.state.indeterminate}
          onChange={(e) => this.setState({
            checked: e.target.checked,
            indeterminate: e.target.indeterminate})
          }
        />
        <label htmlFor='my-checkbox'>My Checkbox</label>

Will render a checkbox looking like this, with the label wrongly positioned and wrong font:
image

Example code here:
https://stackblitz.com/edit/react-wpvkxv

Possible solution

It's missing the Form Field CSS. There is no Form Field React component so this is the best solution I found but it seems wrong to have to do it like this:

  • add form field CSS from package @material/form-field
  • use a wrapping div around the <Checkbox> and <label> with the class "mdc-form-field"

Then it looks as expected:
image

Example code here:
https://stackblitz.com/edit/react-stbwsz?file=Checkbox.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    Unresolved (Archived)Open and unresolved issues and PRs that were closed due to archiving the repository.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions