2

I am maintaining WCAG2.0 'AA' standards on a project in which i need to provide a value to for attribute in checkbox component in react-bootstrap but could not find a proper solution.

Code:: what i am writing jsx

<Checkbox checked={ props.item.selected || false }
onChange={() => {}}>
    <div className="label-text"></div>
</Checkbox>

what i looks like in html:

<div class="checkbox">
    <label title="">
        <input type="checkbox" value="on">
        <div class="label-text"></div>
    </label>
</div>

looking for sort of html :

<label **for="boxa"**>birds</label>
<input **id="boxa"** type="checkbox" name="mytext" />
1
  • The understanding for your code is not quite clear. Please add more details and what I think is you are looking for something like this: stackoverflow.com/a/46956250/7528968 Commented Feb 13, 2018 at 8:03

2 Answers 2

0

You can have a look over the source code of the component from react-bootstrap, but TLDR: they don't provide an option to add a for attribute on a Checkbox component. There's even an eslint disable for it.

Here's the source of the label that accompanies the checkbox.

Sign up to request clarification or add additional context in comments.

Comments

0

If this is reactstrap try this:

import { Form, FormGroup, Label, Input } from 'reactstrap';
<Form>
  <FormGroup>
    <Input type="checkboxId" />
    <Label htmlFor="checkboxId">
      Some input
    </Label>
  </FormGroup>
</Form>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.