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

feat(radio-button-group, checkbox-group): add id prop #7195

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nuria1110
Copy link
Contributor

@nuria1110 nuria1110 commented Feb 7, 2025

fix #7191

Proposed behaviour

  • Add id prop to RadioButtonGroup and CheckboxGroup, if not provided it will be set to a randomly generated GUID. This id is used to set hint text and validation ids, needed for accessibility and testing purposes.
  • Tooltip validation in fieldset components will now render a visually hidden validation message to ensure proper screen reader behaviour.
  • legendInline in CheckboxGroup has no effect with new validation.

Current behaviour

  • RadioButtonGroup and CheckboxGroup do not support id prop.
  • Tooltip validation messages in fieldset components does not get announced by screen readers.
  • legendInline in CheckboxGroup has unexpected behaviour with new validation.
    image

Checklist

  • Commits follow our style guide
  • Related issues linked in commit messages if required
  • Screenshots are included in the PR if useful
  • All themes are supported if required
  • Unit tests added or updated if required
  • Playwright automation tests added or updated if required
  • Storybook added or updated if required
  • Translations added or updated (including creating or amending translation keys table in storybook) if required
  • Typescript d.ts file added or updated if required
  • Related docs have been updated if required

QA

  • Tested in provided StackBlitz sandbox/Storybook
  • Add new Playwright test coverage if required
  • Carbon implementation matches Design System/designs
  • UI Tests GitHub check reviewed if required

Additional context

Testing instructions

Added id prop allows consumers to set a custom id on the group component, otherwise it will be set
to a randomly generated GUID. `id` prop is needed to set hint text and validation ids for
accessibility and testing purposes.

fix #7191
…alidation

Removes legacy props from being passed to the component with new validation designs.
DipperTheDan
DipperTheDan previously approved these changes Feb 10, 2025
@Parsium Parsium self-requested a review February 11, 2025 13:28
</CarbonProvider>
);
};

WithNewValidation.args = {
label: "Radiobutton 1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: good idea to make these args so we can change them via the story's controls 👍

Comment on lines 95 to 96
const { current: uniqueId } = useRef(id || guid());
const inputHintId = useRef(legendHelp ? `${uniqueId}-hint` : undefined);
Copy link
Contributor

@Parsium Parsium Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: to ensure that uniqueId and inputHintId update if either the legendHelp or id props change, it might be better to compute it outside of the useRef hook:

Suggested change
const { current: uniqueId } = useRef(id || guid());
const inputHintId = useRef(legendHelp ? `${uniqueId}-hint` : undefined);
const internalId = useRef(guid());
const uniqueId = id || internalId.current;
const inputHintId = legendHelp ? `${uniqueId}-hint` : undefined;

This way, inputHintId will be re-calculated when the component re-renders, making it reactive if legendHelp or id change, rather than being calculated only on the initial render.

Comment on lines 73 to 74
const inputHintId = useRef(legendHelp ? `${uniqueId}-hint` : undefined);

Copy link
Contributor

@Parsium Parsium Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: similarly to RadioButtonGroup, it might be worth us making uniqueId and inputHintId reactive instead of a ref, so it updates to account that either the id or legendHelp props could change.

Suggested change
const inputHintId = useRef(legendHelp ? `${uniqueId}-hint` : undefined);
const internalId = useRef(guid());
const uniqueId = id || internalId.current;
const inputHintId = legendHelp ? `${uniqueId}-hint` : undefined;

{(error || warning) && (
<ErrorBorder warning={!!(!error && warning)} inline={inline} />
)}
<StyledCheckboxGroup
data-component="checkbox-group"
data-role="checkbox-group"
legendInline={legendInline}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: good spot that this contradicted our documentation 👍

@nuria1110 nuria1110 marked this pull request as ready for review February 14, 2025 11:36
@nuria1110 nuria1110 requested a review from a team as a code owner February 14, 2025 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

ID not passed to ValidationMessage in RadioButtonGroup
3 participants