Skip to content

Commit

Permalink
Merge pull request #134 from BaptWaels/baptwaels_add_id_to_item_checkbox
Browse files Browse the repository at this point in the history
Add id to Items' Checkboxes for a11y
  • Loading branch information
talyak authored Apr 11, 2019
2 parents aabee76 + 5bc91ae commit a035bf3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/components/items/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const Item = ({
>
{!group && (
<Checkbox
id={item.id ? `checkbox-${item.id}` : null}
type="checkbox"
color="primary"
checked={checked}
Expand Down
32 changes: 32 additions & 0 deletions tests/components/items/__snapshots__/item.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exports[`Item default snapshot 1`] = `
checked={false}
color="primary"
disabled={false}
id={null}
indeterminate={false}
type="checkbox"
/>
Expand All @@ -37,6 +38,7 @@ exports[`Item snapshot with border 1`] = `
checked={false}
color="primary"
disabled={false}
id={null}
indeterminate={false}
type="checkbox"
/>
Expand All @@ -60,6 +62,7 @@ exports[`Item snapshot with checked status 1`] = `
checked={true}
color="primary"
disabled={false}
id={null}
indeterminate={false}
type="checkbox"
/>
Expand All @@ -83,6 +86,7 @@ exports[`Item snapshot with disabled 1`] = `
checked={false}
color="primary"
disabled={true}
id={null}
indeterminate={false}
type="checkbox"
/>
Expand Down Expand Up @@ -122,6 +126,7 @@ exports[`Item snapshot with height 1`] = `
checked={false}
color="primary"
disabled={false}
id={null}
indeterminate={false}
type="checkbox"
/>
Expand All @@ -145,6 +150,7 @@ exports[`Item snapshot with indeterminate and checked status 1`] = `
checked={true}
color="primary"
disabled={false}
id={null}
indeterminate={true}
type="checkbox"
/>
Expand All @@ -168,6 +174,7 @@ exports[`Item snapshot with indeterminate status 1`] = `
checked={false}
color="primary"
disabled={false}
id={null}
indeterminate={true}
type="checkbox"
/>
Expand All @@ -177,6 +184,30 @@ exports[`Item snapshot with indeterminate status 1`] = `
</div>
`;

exports[`Item snapshot with item without id 1`] = `
<div
className="item"
onClick={undefined}
style={
Object {
"height": 40,
}
}
>
<WithStyles(Checkbox)
checked={false}
color="primary"
disabled={false}
id={null}
indeterminate={false}
type="checkbox"
/>
<ItemLabel
label="Hi"
/>
</div>
`;

exports[`Item snapshot with valid item 1`] = `
<div
className="item"
Expand All @@ -191,6 +222,7 @@ exports[`Item snapshot with valid item 1`] = `
checked={false}
color="primary"
disabled={false}
id="checkbox-1"
indeterminate={false}
type="checkbox"
/>
Expand Down
8 changes: 8 additions & 0 deletions tests/components/items/item.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ describe("Item", () => {
expect(tree).toMatchSnapshot();
});

test("snapshot with item without id", () => {
const itemWithoutId = { label: "Hi" };

const renderer = new ShallowRenderer();
const tree = renderer.render(<Item item={itemWithoutId} />);
expect(tree).toMatchSnapshot();
});

test("snapshot with checked status", () => {
const renderer = new ShallowRenderer();
const tree = renderer.render(<Item checked={true} />);
Expand Down

0 comments on commit a035bf3

Please sign in to comment.