Skip to content

Commit

Permalink
fix(form): field required indication based on the label instead of th…
Browse files Browse the repository at this point in the history
…e group
  • Loading branch information
MartinWeb committed Sep 18, 2024
1 parent 40fc9a0 commit 525acc1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ exports[`<ChoiceInput> renders ChoiceInput correctly with required 1`] = `
class="col-md-2"
>
<label
class="af-form__group-label"
class="af-form__group-label--required af-form__group-label"
for="oui"
>
Some label
Expand Down
9 changes: 8 additions & 1 deletion packages/Form/core/src/Field.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getComponentClassName } from '@axa-fr/react-toolkit-core';
import React, { ComponentPropsWithoutRef, ReactNode } from 'react';
import classNames from 'classnames';
import FieldError from './FieldError';
import FieldForm from './FieldForm';
import MessageTypes from './MessageTypes';
Expand Down Expand Up @@ -53,7 +54,13 @@ const Field = ({
aria-label={ariaLabelContainer}>
<div className={classNameContainerLabel}>
<label
className="af-form__group-label"
className={classNames(
{
'af-form__group-label--required':
classModifier.includes('required'),
},
'af-form__group-label'
)}
htmlFor={isLabelContainerLinkedToInput ? id : null}>
{label}
</label>
Expand Down
4 changes: 1 addition & 3 deletions packages/Form/core/src/form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
&__group-label {
font-weight: normal;
margin: 0;
}

&__group--required &__group-label {
&:after {
&--required::after {
content: ' *';
color: $color-red-error;
}
Expand Down

0 comments on commit 525acc1

Please sign in to comment.