-
Notifications
You must be signed in to change notification settings - Fork 179
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
refactor(components): add optional data id to Titled List component #6041
Conversation
components/src/lists/TitledList.js
Outdated
@@ -13,6 +13,8 @@ export type TitledListProps = {| | |||
iconName?: ?IconName, | |||
/** props passed down to icon (`className` and `name` are ignored) */ | |||
iconProps?: $Diff<React.ElementProps<typeof Icon>, { name: mixed }>, | |||
/** optional ID for the container */ | |||
dataId?: string, |
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.
so that we don't need to think about dataId
vs data-id
, could we make this prop data-id
instead, mirroring the native element attr?
It would be a bit annoying in the component itself bc of the dash, so when destructuring props we'd have to do const {'data-id': dataId} = props
instead of the simpler const {dataId} = props
.
But the benefit is, when using/consuming these components, we can use the same prop as we'd use for a native element:
<div data-id="Something">
<Spam data-id="Spam" />
<div>
instead of 2 different props for the same attr
<div data-id="Something">
<Spam dataId="Spam" />
<div>
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.
Agree. FWIW, this is the same convention as React: dash-case becomes camelCase except in the case of data and ARIA attributes
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.
Done!
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.
🍨
Overview
This PR partially addresses #5725 by adding an optional data-id to the container wrapping the
TitledList
component in component library. I also updated the relevant PD cypress test to use the new data-id as a selector.Changelog
TitledList
componentReview requests
Code review
E2E tests still pass
Risk assessment
Low