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

[Checkbox] Allows spread properties to reach the actual checkbox element #304

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/Checkbox/Checkbox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CheckboxTestWrapper } from './Checkbox.utils';
const id = 'default';
const label = 'this is a label';
const testId = `${id}-container`;
const inputTestId = `${id}-input`;

const attributeAria = 'aria-checked';
const attributeClass = 'class';
Expand All @@ -18,7 +19,7 @@ describe('Checkbox', () => {
const testTitle = 'test-title';

render(<Checkbox {...defaultProps} title={testTitle} />);
const checkbox = screen.getByTestId(testId);
const checkbox = screen.getByTestId(inputTestId);

expect(checkbox).toBeInTheDocument();
expect(checkbox).toHaveAttribute(attributeTitle, testTitle);
Expand Down
10 changes: 5 additions & 5 deletions src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface CheckboxProperties {
/** An event handler function that will be called when the checkbox's value is changed */
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
/** Border status */
status: 'success' | 'warning' | 'error';
status: 'error' | 'success' | 'warning';
}

const containerBaseStyles = ['m-form-field m-form-field__checkbox'];
Expand All @@ -65,7 +65,7 @@ export const Checkbox = ({
onChange,
status,
...properties
}: CheckboxProperties): ReactElement => {
}: CheckboxProperties & JSX.IntrinsicElements['input']): ReactElement => {
const onChangeHandler = useCallback(
(event: ChangeEvent<HTMLInputElement>): void => {
onChange?.(event);
Expand All @@ -84,20 +84,20 @@ export const Checkbox = ({
<div
className={classnames(containerClasses)}
data-testid={`${id}-container`}
{...properties}
>
<input
id={id}
type='checkbox'
checked={checked}
aria-checked={checked}
aria-labelledby={`${id}-label`}
data-testid={`${id}-input`}
name={name ?? id}
className={classnames(['a-checkbox', inputClassName])}
ref={inputRef}
disabled={disabled}
onChange={onChangeHandler}
{...properties}
data-testid={`${id}-input`}
className={classnames(['a-checkbox', inputClassName])}
/>
<Label
id={`${id}-label`}
Expand Down
Loading