Skip to content

Conversation

juanmitriatti
Copy link
Contributor

UDS-2046

Description

Checklist

  • Tests pass for relevant code changes

Important Reminders

Links

@juanmitriatti juanmitriatti requested a review from a team as a code owner August 25, 2025 16:53
@asu-jenkins-devops
Copy link
Collaborator

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the generation of accessible form field IDs by sanitizing the output of React's useId hook to ensure compliance with HTML ID attribute requirements.

  • Sanitizes useId output to create valid HTML ID attributes for form fields
  • Adds a descriptive prefix "sortBy-" to improve accessibility and semantic meaning
  • Removes special characters that are invalid in HTML ID attributes

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

const sortLabelId = useId();

const rawSortLabelId = useId();
const sortLabelId = `sortBy-${rawSortLabelId.replace(/[^a-zA-Z0-9-_]/g, "")}`;
Copy link

Copilot AI Oct 14, 2025

Choose a reason for hiding this comment

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

The regex pattern [^a-zA-Z0-9-_] allows hyphens and underscores but React's useId() can generate colons which are valid in CSS selectors but should be escaped. Consider using [^a-zA-Z0-9_] to remove hyphens as well, or handle colon escaping specifically if CSS targeting is needed.

Suggested change
const sortLabelId = `sortBy-${rawSortLabelId.replace(/[^a-zA-Z0-9-_]/g, "")}`;
const sortLabelId = `sortBy-${rawSortLabelId.replace(/[^a-zA-Z0-9-_]/g, "").replace(/:/g, "")}`;

Copilot uses AI. Check for mistakes.

Copy link
Contributor

@davidornelas11 davidornelas11 left a comment

Choose a reason for hiding this comment

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

Valid way to sanitize useId

@davidornelas11 davidornelas11 merged commit 5bee7a4 into dev Oct 14, 2025
1 check passed
@davidornelas11 davidornelas11 deleted the UDS-2046 branch October 14, 2025 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants