Skip to content

Commit

Permalink
fix: checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
poplingue committed May 13, 2022
1 parent ff0477d commit ced82e5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
7 changes: 5 additions & 2 deletions example/src/components/Checkbox/Checkbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const CheckboxExample = () => {
return (
<Col>
<CheckboxGroup
isInline
ariaLabel="This is the aria label"
legend="This is the legend"
>
Expand All @@ -19,7 +20,7 @@ const CheckboxExample = () => {
/>
<Checkbox
disabled
label="Label checkbox 2"
label="Label checkbox disabled"
onChange={() => {
}}
value="value-2"
Expand All @@ -30,16 +31,18 @@ const CheckboxExample = () => {
ariaLabel="With colors"
legend="With colors"
message="test"
hint="This is the hint"
messageType="valid"
>
<Checkbox
checked={isChecked}
label="Label checkbox 2"
onChange={() => setIsChecked(!isChecked)}
value="value-2"
hint="Careful"
/>
<Checkbox
label="Label checkbox 2"
label="Label checkbox 3"
value="value-3"
/>
</CheckboxGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/components/interface/Checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ const Checkbox = forwardRef((props, ref) => {
{...dataAttributes.filterAll(remainingProps)}
type="checkbox"
id={checkboxId.current}
name="checkbox"
name={checkboxId.current}
disabled={disabled}
ref={ref}
/>
<label className="fr-label" htmlFor={checkboxId.current}>
{label}
{hint && <p className="fr-hint-text">{hint}</p>}
{hint && <span className="fr-hint-text">{hint}</span>}
</label>
{(message && messageType) && <p className={`fr-${messageType}-text`}>{message}</p>}
</div>
Expand Down
5 changes: 3 additions & 2 deletions src/components/interface/Checkbox/CheckboxGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,19 @@ const CheckboxGroup = ({
}, [color, theme, colorCheckbox]);

return (

<div
className={_className}
{...dataAttributes.getAll(remainingProps)}
>
<fieldset className="fr-fieldset" aria-label={ariaLabel || legend}>
{legend && (
<legend className="fr-fieldset__legend">
<legend className="fr-fieldset__legend fr-text--regular">
{legend}
<span className="fr-hint-text">{hint}</span>
{required && <span className="error"> *</span>}
</legend>
)}
{hint && <p className="fr-hint-text">{hint}</p>}
<div className="fr-fieldset__content">
{children}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports[`<Checkbox /> renders correctly 1`] = `
>
<input
id="xxxxxxx"
name="checkbox"
name="xxxxxxx"
type="checkbox"
value="value"
/>
Expand Down
6 changes: 4 additions & 2 deletions src/components/interface/Download/DownloadGroup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Children } from 'react';
import React, { Children, useRef } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { v4 as uuidv4 } from 'uuid';
import dataAttributes from '../../../utils/data-attributes';

/**
Expand All @@ -13,6 +14,7 @@ const DownloadGroup = ({
title,
...remainingProps
}) => {
const id = useRef(uuidv4());
const _className = classNames(
'fr-downloads-group fr-downloads-group--bordered',
className,
Expand All @@ -22,7 +24,7 @@ const DownloadGroup = ({
<div {...dataAttributes.getAll(remainingProps)} className={_className}>
<h4 className="fr-downloads-group__title">{title}</h4>
<ul>
{Children.toArray(children).map((child) => <li key={child.props.name}>{child}</li>)}
{Children.toArray(children).map((child) => <li key={`${child.props.label}${id.current}`}>{child}</li>)}
</ul>
</div>
);
Expand Down

0 comments on commit ced82e5

Please sign in to comment.