Maël
Développeur front-end
Examples en React, mais applicables partout
Projets React + design system chez Keytrade Bank
Conseils techniques, pratiques et/ou organisationnels
<Label for='name'>Nom</Label>
<Input id='name' />
// Input.jsx
return (
<input id={props.id} />
)
// Label.jsx
return (
<label htmlFor={props.for}>
)
<Input />
<div>Nom</div>
<Input/>
<Label>Nom</Label>
<Input/>
//Input.jsx
Input.propTypes = {
label: PropTypes.string.isRequired,
hideLabel: PropTypes.bool
}
props.hideLabel
? <VisuallyHidden>
<label htmlFor={props.id || props.label}>{props.label}</label>
</VisuallyHidden>
: <label htmlFor={props.id || props.label}>{props.label}</label>
<Input label='search for an account' hideLabel />
Title.defaultProps = {
size: 'md',
level: ?
};
<Title size="lg" level="h1">Un titre de page</Title>
Title.propTypes = {
level: PropTypes.oneOf(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']).isRequired
};
// Modal.jsx
useEffect(() => {
modalRef.focus();
});
return (
<div tabindex='-1' ref={modalRef}>
...
</div>
)
tests d'a11y 😀
const comp = mount(<Input label='example label' hideLabel />);
it('should render a label element', () => {
expect(comp.find('label').length).toEqual(1);
});
it('should render the label text', () => {
expect(comp.contains('example label')).toBe(true);
});
<div onClick={} />