Skip to content

fix: add field title for minimum and maximum fields - #884

Closed
priscila-moneo wants to merge 0 commit into
masterfrom
fix/add-title-maximum-minimum-fields
Closed

fix: add field title for minimum and maximum fields#884
priscila-moneo wants to merge 0 commit into
masterfrom
fix/add-title-maximum-minimum-fields

Conversation

@priscila-moneo

@priscila-moneo priscila-moneo commented Apr 20, 2026

Copy link
Copy Markdown

ref: https://app.clickup.com/t/86b8ejhum

image

Summary by CodeRabbit

  • Style
    • Added clear labels to quantity input fields (minimum and maximum) with proper form associations to enhance usability and accessibility.

@coderabbitai

coderabbitai Bot commented Apr 20, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

MUI InputLabel components were added to the "Quantity" meta fields in the additional input form, with each label properly linked to its corresponding Formik field via htmlFor attribute and localized text.

Changes

Cohort / File(s) Summary
Quantity Field Labels
src/components/mui/formik-inputs/additional-input/additional-input.js
Added MUI InputLabel components for minimum_quantity and maximum_quantity fields with localized label text and proper htmlFor linking.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 Labels on the fields, oh what a delight!
Minimum and maximum, now shining bright,
Formik and MUI dance in harmony,
Accessibility blooms like clover, you see! 🍀✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding InputLabel components with titles for the minimum and maximum quantity fields in the form.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/add-title-maximum-minimum-fields

Warning

Review ran into problems

🔥 Problems

Timed out fetching pipeline failures after 30000ms


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/components/mui/formik-inputs/additional-input/additional-input.js (1)

116-120: Same translation key used for labels and placeholders.

Both InputLabel components use translation keys from the placeholders namespace:

  • Line 118: "additional_inputs.placeholders.meta_field_minimum_quantity"
  • Line 134: "additional_inputs.placeholders.meta_field_maximum_quantity"

These same keys are reused for the placeholder props of the MuiFormikTextField components (lines 123-124, 139-140). While this might be intentional to keep the text consistent, labels and placeholders typically serve different semantic purposes:

  • Labels describe what the field is for (e.g., "Minimum Quantity")
  • Placeholders provide example input or hints (e.g., "Enter minimum value")
💡 Consider using separate translation keys for labels

Create dedicated label translation keys:

-                <InputLabel htmlFor={buildFieldName("minimum_quantity")}>
-                  {T.translate(
-                    "additional_inputs.placeholders.meta_field_minimum_quantity"
-                  )}
-                </InputLabel>
+                <InputLabel htmlFor={buildFieldName("minimum_quantity")}>
+                  {T.translate(
+                    "additional_inputs.meta_field_minimum_quantity"
+                  )}
+                </InputLabel>

And similarly for maximum_quantity. This provides clearer separation and allows different text if needed in the future.

Also applies to: 132-136

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/mui/formik-inputs/additional-input/additional-input.js` around
lines 116 - 120, The InputLabel components are using the
"additional_inputs.placeholders.*" translation keys currently also used for
field placeholders; update the labels to use distinct label keys (e.g.,
"additional_inputs.labels.meta_field_minimum_quantity" and
"additional_inputs.labels.meta_field_maximum_quantity") and update the
InputLabel calls in additional-input.js to reference those new keys instead of
the placeholders keys; leave the MuiFormikTextField placeholder props
referencing the existing placeholders keys so labels (InputLabel) and
placeholders (MuiFormikTextField) are semantically separated and can be edited
independently.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/mui/formik-inputs/additional-input/additional-input.js`:
- Around line 116-120: The label-input association is broken because
InputLabel's htmlFor expects an explicit id on the underlying TextField; update
the MuiFormikTextField component to generate and pass a sanitized id derived
from the field name (e.g., implement a sanitizeId function that replaces
brackets and dots with hyphens) and set id={sanitizeId(name)} on the TextField,
and then update the parent that uses buildFieldName("minimum_quantity") so the
InputLabel uses the same sanitized id
(htmlFor={sanitizeId(buildFieldName("minimum_quantity"))}) to restore correct
accessibility linking.

---

Nitpick comments:
In `@src/components/mui/formik-inputs/additional-input/additional-input.js`:
- Around line 116-120: The InputLabel components are using the
"additional_inputs.placeholders.*" translation keys currently also used for
field placeholders; update the labels to use distinct label keys (e.g.,
"additional_inputs.labels.meta_field_minimum_quantity" and
"additional_inputs.labels.meta_field_maximum_quantity") and update the
InputLabel calls in additional-input.js to reference those new keys instead of
the placeholders keys; leave the MuiFormikTextField placeholder props
referencing the existing placeholders keys so labels (InputLabel) and
placeholders (MuiFormikTextField) are semantically separated and can be edited
independently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 90546c47-487c-4c6e-a25b-414f4d6b2288

📥 Commits

Reviewing files that changed from the base of the PR and between b109482 and 28b8c9d.

📒 Files selected for processing (1)
  • src/components/mui/formik-inputs/additional-input/additional-input.js

Comment on lines +116 to +120
<InputLabel htmlFor={buildFieldName("minimum_quantity")}>
{T.translate(
"additional_inputs.placeholders.meta_field_minimum_quantity"
)}
</InputLabel>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check how MuiFormikTextField handles the id attribute and verify TextField usage

# Check if MuiFormikTextField explicitly passes id prop to TextField
rg -n -A 10 'const MuiFormikTextField' src/components/mui/formik-inputs/mui-formik-textfield.js

# Search for any other instances where InputLabel with htmlFor is used with buildFieldName
rg -n -C 3 'htmlFor=\{buildFieldName' src/

Repository: fntechgit/summit-admin

Length of output: 1799


🌐 Web query:

MUI TextField id generation from name prop with array notation bracket syntax

💡 Result:

No, MUI TextField does not generate the id from the name prop, including when using array notation bracket syntax like "items[0]". The id prop must be explicitly provided for proper accessibility linking between the label, input, and helper text. If no id is provided, recent versions (post-2021 proposals) may auto-generate a random id using React's useId hook, but it is not derived from the name prop. The name prop is forwarded to the underlying input element for form submission purposes, but id generation is independent. Official docs list id and name as separate props with no mention of automatic derivation. Source code inspection and GitHub issues/PRs confirm no such feature exists; proposals for auto-generation (not name-based) were discussed but marked duplicate or not merged as described. For array fields (e.g., name="items[0]"), developers typically manually set unique ids like id={items-${index}} when rendering dynamic lists, as seen in StackOverflow examples.

Citations:


🌐 Web query:

HTML id attribute allowed characters restrictions brackets

💡 Result:

In HTML5 (current standard as of 2026), the id attribute has minimal restrictions: it must contain at least one character, must not contain any ASCII whitespace (space, tab, LF, FF, CR), and must be unique within the document. There are no other restrictions on characters, including brackets like [] or {}. Brackets (square brackets [], curly braces {}, parentheses ) are fully allowed in id values per the spec. MDN confirms the value "may contain any other Unicode character" except ASCII whitespace. However, special characters like brackets, ?, :, ., # require escaping in CSS selectors (e.g., #my[id]) or JavaScript querySelector (using CSS.escape), and may not be valid unquoted JS identifiers. For best compatibility with CSS/JS without escaping, use valid CSS identifiers: starting with letter/hyphen/underscore, followed by letters, digits, hyphens, underscores. HTML4 had stricter rules (start with letter, only specific chars), but HTML5 is permissive. Examples: - Valid: id="my-id[1]", id="test{}", id="123[]" - Invalid: id="", id="my id" (space), id with only whitespace.

Citations:


🌐 Web query:

Material-UI TextField accessibility htmlFor id linking formik array notation

💡 Result:

To achieve proper accessibility in Material-UI (MUI) TextField when used with Formik, especially in array notation (e.g., FieldArray with names like friends[0].name), follow these guidelines based on official documentation: ## Core Accessibility Requirement MUI TextField requires a unique id prop on the TextField component. This id is used internally to: - Link the InputLabel via htmlFor={id} (automatically handled by TextField). - Link the input element (id passed to ). - Link helper text via aria-describedby. Without an explicit id, labels won't associate properly with inputs for screen readers, violating WCAG 1.3.1 (Info and Relationships). Example DOM structure needed: Name Helper text ## With Formik Arrays Formik FieldArray uses dot/bracket notation for names: friends.${index} or friends[${index}]. The name prop handles form state binding, but does not automatically set id. ### Solution 1: Custom TextFieldProps Component (Recommended) Create a Formik-compatible wrapper that auto-generates id from name: jsx import React from 'react'; import { useField, FieldAttributes } from 'formik'; import { TextField } from '@mui/material'; interface FormikTextFieldProps { label: string; // other MUI props } const FormikMuiTextField: React.FC<FieldAttributes> = ({ label, ...props }) => { const [field, meta] = useField(props); const id = field-${field.name.replace(/[|]|./g, '-')}; // e.g., "field-friends-0-name" return ( <TextField {...field} id={id} label={label} error={meta.touched && Boolean(meta.error)} helperText={meta.touched && meta.error ? meta.error : undefined} {...props} /> ); }; Usage in FieldArray: jsx {({ push, remove }) => ( <> {values.friends.map((friend, index) => (

<FormikMuiTextField name={friends[${index}].name} label={Friend ${index + 1} Name} /> <FormikMuiTextField name={friends[${index}].email} label={Friend ${index + 1} Email} /> <button type="button" onClick={ => remove(index)}>Remove
))} <button type="button" onClick={ => push({ name: '', email: '' })}>Add Friend </> )} ### Solution 2: Manual id with Formik Field Render Prop jsx {({ field, meta }) => { const id = friends-${index}-name; return ( <TextField {...field} id={id} label="Name" error={meta.touched && Boolean(meta.error)} helperText={meta.touched ? meta.error : undefined} /> ); }} ### Solution 3: Use formik-mui Library Libraries like formik-mui (https://github.com/stackworx/formik-mui) handle this automatically: bash npm install formik-mui jsx import { TextField } from 'formik-mui'; These libraries generate proper ids from name internally. ## Key Points - Always provide unique id matching the field name (sanitized for HTML IDs: replace [] with -, dots with -). - MUI v5+ auto-generates id if missing (via useId), but explicit id ensures consistency, especially server-side/client-side hydration. - Formik's name only binds state; doesn't affect a11y linking. - Test with screen readers (NVDA/VoiceOver) or axe DevTools. This ensures full a11y compliance while supporting dynamic Formik arrays.

Citations:


Fix label-input association for accessibility: InputLabel htmlFor requires explicit id prop on TextField.

The MuiFormikTextField component must explicitly pass an id prop to the underlying MUI TextField. Currently, without an explicit id, MUI generates a random auto-id that won't match the htmlFor attribute on InputLabel, breaking the label-to-input association. This violates WCAG 1.3.1 (Info and Relationships) and prevents screen readers from properly associating labels with inputs.

Since the field name uses array notation like meta_fields[0].minimum_quantity, the id must be sanitized (replace brackets and dots with hyphens) to create a valid HTML id.

Solution: Modify MuiFormikTextField to generate and pass a sanitized id:

Example fix
// In MuiFormikTextField component
const sanitizeId = (name) => name.replace(/[\[\]\.]/g, '-');

<TextField
  id={sanitizeId(name)}
  name={name}
  // ... other props
/>

Then in the parent component, ensure InputLabel references the same sanitized id:

<InputLabel htmlFor={sanitizeId(buildFieldName("minimum_quantity"))}>
  {T.translate("additional_inputs.placeholders.meta_field_minimum_quantity")}
</InputLabel>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/mui/formik-inputs/additional-input/additional-input.js` around
lines 116 - 120, The label-input association is broken because InputLabel's
htmlFor expects an explicit id on the underlying TextField; update the
MuiFormikTextField component to generate and pass a sanitized id derived from
the field name (e.g., implement a sanitizeId function that replaces brackets and
dots with hyphens) and set id={sanitizeId(name)} on the TextField, and then
update the parent that uses buildFieldName("minimum_quantity") so the InputLabel
uses the same sanitized id
(htmlFor={sanitizeId(buildFieldName("minimum_quantity"))}) to restore correct
accessibility linking.

@martinquiroga-exo martinquiroga-exo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@santipalenque santipalenque left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@smarcet smarcet left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@priscila-moneo

Copy link
Copy Markdown
Author

this was replaced by OpenStackweb/openstack-uicore-foundation#230

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.

4 participants