fix(dropdown): Disallow invalid & warn when readonly or disabled#20803
Conversation
✅ Deploy Preview for v11-carbon-web-components ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for v11-carbon-react ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for carbon-elements ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #20803 +/- ##
==========================================
+ Coverage 92.37% 92.39% +0.01%
==========================================
Files 515 515
Lines 37605 37629 +24
Branches 5782 5740 -42
==========================================
+ Hits 34739 34766 +27
+ Misses 2716 2714 -2
+ Partials 150 149 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
riddhybansal
left a comment
There was a problem hiding this comment.
Hey this looks good
Small Suggestions for Improvement
Code Consistency
Consider using useNormalizedInputProps in all components rather than creating separate validation logic:
normalizedProps = useNormalizedInputProps({
id, disabled, readOnly, invalid, invalidText, warn, warnText,
});
Then reference normalizedProps.invalid and normalizedProps.warn for validation states
Our input controls already use this pattern, which makes future fixes simpler (just update the hook once).
Here is the reference PR
|
The changes have been applied. Could you please add the Hacktoberfest label? If possible, also include it on pull request #20791 |
riddhybansal
left a comment
There was a problem hiding this comment.
Hi there, the React implementation works as expected, but I've identified an issue with the web-components version. When a component is in an invalid state and I enable the disabled attribute, the invalid styles correctly disappear. However, when I subsequently remove the disabled attribute while the component remains invalid, the invalid styles fail to reappear as they should.
Screen.Recording.2025-10-28.at.11.57.19.AM.mov
|
I've completed the requested changes. Do you have any estimate on when my other pull request might be reviewed? |
maradwan26
left a comment
There was a problem hiding this comment.
Thanks for contributing! Just one small comment, the rest LGTM
|
@riddhybansal could you approve this PR so we can merge it? I think you requested some changes. Thanks! |
f8ac84e
Closes #20723
Fix Dropdown showing validation states when disabled or readonly
Description
Prevents dropdown components (React and Web Components) from displaying invalid/warn states when in disabled or readonly mode, as users cannot interact with non-interactive components to fix validation issues.
Changelog
Changed
React Component (
Dropdown.tsx):isInteractiveflag (!readOnly && !disabled) to conditionally show validation statesshowInvalidandshowWarningbased on interactivityWeb Components (
dropdown.ts):invalidandwarnproperties fromreflect: truetoreflect: falseupdated()method to control when attributes appear on host elementisInteractivelogic in_classesgetter andrender()methodshouldUpdate()to properly enable/disable child items whendisabledproperty togglesTesting / Reviewing
React Component:
invalid={true}andinvalidText="Error message"disabled={true}disabled={false}readOnly={true}warnpropWeb Components:
invalidandinvalid-text="Error message"invalidattribute exists on<cds-dropdown>disabledattributeinvalidattribute is removed from hostread-onlyattributeExpected behavior:
disabled=trueorreadOnly=true: No validation classes, no validation icons, no validation text, no validation attributes on host elementPrevious behavior:
Accessibility Impact
Improved:
aria-describedbycorrectly associates helper text instead of validation text when non-interactivePR Checklist
As the author of this PR, before marking ready for review, confirm you:
More details can be found in the pull request guide