Skip to content

Commit

Permalink
fix: do not display empty <label></label> (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddecrulle committed Jul 11, 2024
1 parent 5507541 commit c7cc7df
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 62 deletions.
16 changes: 9 additions & 7 deletions src/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,15 @@ export const Input = memo(
id={id}
{...rest}
>
<label
className={cx(fr.cx("fr-label", hideLabel && "fr-sr-only"), classes.label)}
htmlFor={inputId}
>
{label}
{hintText !== undefined && <span className="fr-hint-text">{hintText}</span>}
</label>
{Boolean(label || hintText) && (
<label
className={cx(fr.cx("fr-label", hideLabel && "fr-sr-only"), classes.label)}
htmlFor={inputId}
>
{label}
{hintText !== undefined && <span className="fr-hint-text">{hintText}</span>}
</label>
)}
{(() => {
const nativeInputOrTextArea = (
<NativeInputOrTextArea
Expand Down
18 changes: 10 additions & 8 deletions src/Range.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,16 @@ export const Range = memo(
id={`${id}-group`}
{...rest}
>
<label className={cx(fr.cx("fr-label"), classes.label)} id={labelId}>
{label}
{hintText !== undefined && (
<span className={cx(fr.cx("fr-hint-text"), classes.hintText)}>
{hintText}
</span>
)}
</label>
{Boolean(label || hintText) && (
<label className={cx(fr.cx("fr-label"), classes.label)} id={labelId}>
{label}
{hintText !== undefined && (
<span className={cx(fr.cx("fr-hint-text"), classes.hintText)}>
{hintText}
</span>
)}
</label>
)}
<div
className={cx(
fr.cx(
Expand Down
26 changes: 14 additions & 12 deletions src/SegmentedControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,20 @@ export const SegmentedControl = memo(
name={segmentedName}
type="radio"
/>
<label
className={cx(
fr.cx(
segment.iconId !== undefined && segment.iconId,
"fr-label"
),
classes["element-each__label"]
)}
htmlFor={segmentId}
>
{segment.label}
</label>
{segment.label && (
<label
className={cx(
fr.cx(
segment.iconId !== undefined && segment.iconId,
"fr-label"
),
classes["element-each__label"]
)}
htmlFor={segmentId}
>
{segment.label}
</label>
)}
</div>
);
})}
Expand Down
12 changes: 8 additions & 4 deletions src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,14 @@ export const Select = memo(
style={style}
{...rest}
>
<label className={fr.cx("fr-label")} htmlFor={selectId}>
{label}
{hint !== undefined && <span className={fr.cx("fr-hint-text")}>{hint}</span>}
</label>
{Boolean(label || hint) && (
<label className={fr.cx("fr-label")} htmlFor={selectId}>
{label}
{hint !== undefined && (
<span className={fr.cx("fr-hint-text")}>{hint}</span>
)}
</label>
)}
<select
className={cx(fr.cx("fr-select"), nativeSelectProps.className)}
id={selectId}
Expand Down
10 changes: 6 additions & 4 deletions src/SelectNext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,12 @@ function NonMemoizedNonForwardedSelect<T extends SelectProps.Option[]>(
style={style}
{...rest}
>
<label className={fr.cx("fr-label")} htmlFor={selectId}>
{label}
{hint !== undefined && <span className={fr.cx("fr-hint-text")}>{hint}</span>}
</label>
{Boolean(label || hint) && (
<label className={fr.cx("fr-label")} htmlFor={selectId}>
{label}
{hint !== undefined && <span className={fr.cx("fr-hint-text")}>{hint}</span>}
</label>
)}
<select
className={cx(fr.cx("fr-select"), nativeSelectProps?.className)}
id={selectId}
Expand Down
22 changes: 12 additions & 10 deletions src/ToggleSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,18 @@ export const ToggleSwitch = memo(
checked={props_checked ?? checked}
name={name}
/>
<label
className={cx(fr.cx("fr-toggle__label"), classes.label)}
htmlFor={inputId}
{...(showCheckedHint && {
"data-fr-checked-label": t("checked"),
"data-fr-unchecked-label": t("unchecked")
})}
>
{label}
</label>
{label && (
<label
className={cx(fr.cx("fr-toggle__label"), classes.label)}
htmlFor={inputId}
{...(showCheckedHint && {
"data-fr-checked-label": t("checked"),
"data-fr-unchecked-label": t("unchecked")
})}
>
{label}
</label>
)}
{helperText && (
<p className={cx(fr.cx("fr-hint-text"), classes.hint)} id={hintId}>
{helperText}
Expand Down
10 changes: 6 additions & 4 deletions src/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ export const Upload = memo(
)}
ref={ref}
>
<label className={fr.cx("fr-label")} aria-disabled={disabled} htmlFor={inputId}>
{label}
<span className={fr.cx("fr-hint-text")}>{hint}</span>
</label>
{Boolean(label || hint) && (
<label className={fr.cx("fr-label")} aria-disabled={disabled} htmlFor={inputId}>
{label}
<span className={fr.cx("fr-hint-text")}>{hint}</span>
</label>
)}
<input
aria-describedby={messageId}
aria-disabled={disabled}
Expand Down
16 changes: 9 additions & 7 deletions src/blocks/PasswordInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ export const PasswordInput = memo(
ref={ref}
{...rest}
>
<label
className={cx(fr.cx("fr-label", hideLabel && "fr-sr-only"), classes.label)}
htmlFor={inputId}
>
{label}
{hintText !== undefined && <span className="fr-hint-text">{hintText}</span>}
</label>
{Boolean(label || hintText) && (
<label
className={cx(fr.cx("fr-label", hideLabel && "fr-sr-only"), classes.label)}
htmlFor={inputId}
>
{label}
{hintText !== undefined && <span className="fr-hint-text">{hintText}</span>}
</label>
)}
<div className={fr.cx("fr-input-wrap")}>
<input
{...nativeInputProps}
Expand Down
14 changes: 8 additions & 6 deletions src/shared/Fieldset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,14 @@ export const Fieldset = memo(
name={radioName}
{...nativeInputProps}
/>
<label className={fr.cx("fr-label")} htmlFor={getInputId(i)}>
{label}
{hintText !== undefined && (
<span className={fr.cx("fr-hint-text")}>{hintText}</span>
)}
</label>
{Boolean(label || hintText) && (
<label className={fr.cx("fr-label")} htmlFor={getInputId(i)}>
{label}
{hintText !== undefined && (
<span className={fr.cx("fr-hint-text")}>{hintText}</span>
)}
</label>
)}
{"illustration" in rest && (
<div className={fr.cx("fr-radio-rich__img")}>
{rest.illustration}
Expand Down

0 comments on commit c7cc7df

Please sign in to comment.