-
Notifications
You must be signed in to change notification settings - Fork 71
chore(packages) avoid data-lgid
and data-testid
attributes being duplicated in components
#3184
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 148ee52 The changes in this PR will be included in the next version bump. This PR includes changesets to release 96 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Size Change: +930 B (+0.06%) Total Size: 1.6 MB
ℹ️ View Unchanged
|
})} | ||
data-lgid={lgIds.root} | ||
data-testid={lgIds.root} | ||
data-lgid={lgIds.label} |
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.
One of the reasons we pass the root to label and description is because <Label>
and <Description>
already generate their own specific lgids internally.
leafygreen-ui/packages/typography/src/Label/Label.tsx
Lines 38 to 39 in 9b2d156
data-lgid={getLgIds(dataLgId).label} | |
data-testid={getLgIds(dataLgId).label} |
So if you pass lgids.root
, the root is lg-checkbox
and the id generated in <Label>
will be lg-checkbox-label
.
However, if we pass lgIds.label
, that will pass lg-checkbox-label
to <Label>
, which will generate lg-checkbox-label-label
.
The first approach allows us to avoid duplication in the id 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.
Ahh I see. Wouldn't it make more sense (and in alignment with the style-guide / BEM-like) for the Label
component to have its own getLgIds
function? 🤔 I mean, Label
is not a "child element" of some "typography block".
I've pushed a suggestion to work around this in the simplest possible way I could imagine.
leafygreen-ui/packages/typography/src/Description/Description.tsx
Lines 36 to 41 in 148ee52
const lgIds = getLgIds(dataLgId ?? getLgIds().description); | |
return ( | |
<Component | |
data-lgid={lgIds.root} | |
data-testid={lgIds.root} |
06a802e
to
bb28eaa
Compare
b004364
to
148ee52
Compare
✍️ Proposed changes
Merging this PR will:
data-lgid
ordata-testid
attributes are referencing the same id.✅ Checklist
For new components
For bug fixes, new features & breaking changes
pnpm changeset
and documented my changes🧪 How to test changes