Skip to content

Commit

Permalink
fix(react): remove unnecessary input and adjust role (#12301)
Browse files Browse the repository at this point in the history
* fix(react): remove unnecessary input and adjust role

* chore(react): fix tests

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
abbeyhrt and kodiakhq[bot] authored Oct 14, 2022
1 parent 6d90078 commit 6f7797f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 33 deletions.
11 changes: 11 additions & 0 deletions e2e/components/Tile/Tile-test.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,15 @@ test.describe('Tile', () => {
});
await expect(page).toHaveNoACViolations('Tile');
});

test('accessibility-checker selectable tile @avt', async ({ page }) => {
await visitStory(page, {
component: 'SelectableTile',
id: 'components-tile--selectable',
globals: {
theme: 'white',
},
});
await expect(page).toHaveNoACViolations('SelectableTile');
});
});
55 changes: 23 additions & 32 deletions packages/react/src/components/Tile/next/Tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,6 @@ export const SelectableTile = React.forwardRef(function SelectableTile(
},
className
);
const inputClasses = cx(`${prefix}--tile-input`, {
[`${prefix}--tile-input--checked`]: isSelected,
});

// TODO: rename to handleClick when handleClick prop is deprecated
function handleOnClick(evt) {
Expand Down Expand Up @@ -231,36 +228,30 @@ export const SelectableTile = React.forwardRef(function SelectableTile(
}

return (
<>
<input
checked={isSelected}
className={inputClasses}
disabled={disabled}
id={id}
name={name}
onChange={!disabled ? handleChange : null}
ref={ref}
tabIndex={-1}
title={title}
type="checkbox"
value={value}
/>
{/* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */}
<label
className={classes}
htmlFor={id}
onClick={!disabled ? handleOnClick : null}
onKeyDown={!disabled ? handleOnKeyDown : null}
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
tabIndex={!disabled ? tabIndex : null}
{...rest}>
<span
className={`${prefix}--tile__checkmark ${prefix}--tile__checkmark--persistent`}>
{isSelected ? <CheckboxCheckedFilled /> : <Checkbox />}
</span>
<span className={`${prefix}--tile-content`}>{children}</span>
<div
className={classes}
onClick={!disabled ? handleOnClick : null}
role="checkbox"
aria-checked={isSelected}
disabled={disabled}
onKeyDown={!disabled ? handleOnKeyDown : null}
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
tabIndex={!disabled ? tabIndex : null}
value={value}
name={name}
ref={ref}
id={id}
onChange={!disabled ? handleChange : null}
title={title}
{...rest}>
<span
className={`${prefix}--tile__checkmark ${prefix}--tile__checkmark--persistent`}>
{isSelected ? <CheckboxCheckedFilled /> : <Checkbox />}
</span>
<label htmlFor={id} className={`${prefix}--tile-content`}>
{children}
</label>
</>
</div>
);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/Tile/next/Tile.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const ClickableWithLayer = () => {

export const Selectable = () => {
return (
<SelectableTile id="tile-1" name="tiles">
<SelectableTile id="tile-1" name="tiles" value="selectable">
Selectable
</SelectableTile>
);
Expand Down

0 comments on commit 6f7797f

Please sign in to comment.