onCheck: (checked: boolean, id?: string) => void;
right?: boolean;
thirdState?: boolean;
+ title?: string;
}
export default class Checkbox extends React.PureComponent<Props> {
};
render() {
- const { children, disabled, loading, right } = this.props;
+ const { checked, children, disabled, id, loading, right, thirdState, title } = this.props;
const className = classNames('icon-checkbox', {
- 'icon-checkbox-checked': this.props.checked,
- 'icon-checkbox-single': this.props.thirdState,
+ 'icon-checkbox-checked': checked,
+ 'icon-checkbox-single': thirdState,
'icon-checkbox-disabled': disabled
});
if (children) {
return (
<a
+ aria-checked={checked}
className={classNames('link-checkbox', this.props.className, {
note: disabled,
disabled
})}
href="#"
- id={this.props.id}
- onClick={this.handleClick}>
+ id={id}
+ onClick={this.handleClick}
+ role="checkbox"
+ title={title}>
{right && children}
<DeferredSpinner loading={Boolean(loading)}>
<i className={className} />
return (
<a
+ aria-checked={checked}
className={classNames(className, this.props.className)}
href="#"
- id={this.props.id}
+ id={id}
onClick={this.handleClick}
+ role="checkbox"
+ title={title}
/>
);
}
import Checkbox from '../Checkbox';
import { click } from '../../../helpers/testUtils';
+it('should render', () => {
+ const checkbox = shallow(<Checkbox checked={true} onCheck={() => {}} title="Title value" />);
+ expect(checkbox).toMatchSnapshot();
+});
+
it('should render unchecked', () => {
const checkbox = shallow(<Checkbox checked={false} onCheck={() => true} />);
expect(checkbox.is('.icon-checkbox-checked')).toBeFalsy();
+ expect(checkbox.prop('aria-checked')).toBe(false);
});
it('should render checked', () => {
const checkbox = shallow(<Checkbox checked={true} onCheck={() => true} />);
expect(checkbox.is('.icon-checkbox-checked')).toBeTruthy();
+ expect(checkbox.prop('aria-checked')).toBe(true);
});
it('should render disabled', () => {
// Jest Snapshot v1, https://goo.gl/fbAQLP
+exports[`should render 1`] = `
+<a
+ aria-checked={true}
+ className="icon-checkbox icon-checkbox-checked"
+ href="#"
+ onClick={[Function]}
+ role="checkbox"
+ title="Title value"
+/>
+`;
+
exports[`should render the checkbox on the right 1`] = `
<a
+ aria-checked={true}
className="icon-checkbox icon-checkbox-checked"
href="#"
onClick={[Function]}
+ role="checkbox"
/>
`;