-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
ComboboxControl: use custom prefix when generating the instanceId #42134
ComboboxControl: use custom prefix when generating the instanceId #42134
Conversation
@@ -287,3 +288,39 @@ _default.args = { | |||
__next36pxDefaultSize: false, | |||
allowReset: false, | |||
}; | |||
|
|||
export function TestDuplicateInstanceIds( args ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For test purposes only. I will remove this storybook example before merging
Size Change: +3 B (0%) Total Size: 1.25 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ciampo LGTM.
The reason why I did not do this myself is I did not know if this would be against style guide naming convention to have a double component prefix before the instance ID. If you think it is fine, that is a simple enough fix for me.
Thank you for the quick review!
There isn't a convention (at least that I'm aware of), especially since the Cc'ing @sarayourfriend (who may have some additional context on this function) and @mirka in case I'm missing anything here, before merging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tests well for me. Thanks, @ciampo!
This reverts commit e832770c5db0cb4393d7169cc4141ac2553cb4d4.
d6f89ef
to
7a21bfa
Compare
What?
Fixes #42112
Fixes a bug which caused different
input
elements to be assigned the sameid
in case aComboboxControl
and aFormTokenField
components are rendered in the same page and are assigned the sameinstanceId
.I initially wanted to add a unit test for this, but:
ComboboxControl
has no unit tests (😱)FormTokenField
's tests are written withReact.TestUtils
(which I never used before)...and so, for the sake of landing this fix quickly, I decided to skip unit tests.
Why?
Every ID assigned to an element in a page should be unique — non-unique IDs technically make the page's markup non-valid and can cause severe difficulties to users relying on assistive technology.
See #42112 (comment) for a more detailed explanation.
How?
In order to avoid the
TokenInput
component to receive the sameinstanceId
from bothComboboxControl
andFormTokenField
, theComboboxControl
component now passes a customprefix
when callinguseInstanceId
. This means that, while theid
s received byFormTokenField
are simple numbers (1, 2, 3..), theid
s generated forComboboxControl
will all be prefixed (i.e.combobox-control-1
,combobox-control-2
,combobox-control-3
...)Testing Instructions
Follow the instructions in #42112 's description, the bug should be not reproducible anymore.
Alternatively, I've added a temporary Storybook example:
npm run storybook:dev
and visit http://localhost:50240/?path=/story/components-comboboxcontrol--test-duplicate-instance-idsComboboxControl
andFormTokenField
receive the sameinstanceId
internally)input
elements rendered in the page, assess that they have differentid
sFor completeness, undo the changes to
packages/components/src/combobox-control/index.js
introduced from this PR, repeat the points above, and verify that the bug can be reproduced.Screenshots or screencast