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

fix: do not display empty <label></label> #275

Merged
merged 1 commit into from
Jul 11, 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
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
Loading