fix(BBBCheckbox): respect caller-provided id prop & feat(BBBCheckbox): add dataTest prop for the underlying input - #80
Merged
Conversation
BBBCheckbox always rendered with an internally generated id from
useId(), because {...props} was spread before the explicit id
attribute, so the generated value silently overwrote any id passed
by the caller. This made it impossible to target the rendered input
by a known id and broke the label/htmlFor association whenever a
custom id was expected.
Destructure id from props and fall back to useId() only when the
caller does not provide one, reusing the resolved value for both the
checkbox input and the label's htmlFor attribute.
BBBCheckbox has no way to tag its rendered <input> for test
selectors. Spreading an arbitrary data-test through {...props} does
not work: MUI's SwitchBase only forwards explicitly recognized props
(id, checked, name, inputProps) to the actual <input>, so anything
else spread through falls into the outer wrapper <span> instead —
the same class of issue fixed for id in the previous commit.
Add an explicit dataTest prop, matching the convention already used
by BBButton and BBBInput, and route it through MUI's inputProps so
it lands on the real <input>, merging with any inputProps the caller
already passes directly.
dataTest prop for the underlying input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes an issue with the ID passed to the BBBCheckbox component, which was silently overridden. Also, adds a explicit data test prop to this component, in order to make testing easier.
Closes Issue(s)
Closes #77