Skip to content

Commit 06a802e

Browse files
committed
Enable Label and Description overrides
1 parent 8e7e44a commit 06a802e

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

packages/typography/src/Description/Description.spec.tsx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
import React, { ReactNode } from 'react';
1+
import React from 'react';
22
import { render } from '@testing-library/react';
33

4-
import { PolymorphicAs } from '@leafygreen-ui/polymorphic';
5-
64
import Description from './Description';
75

8-
const renderDescription = ({
9-
as,
10-
children = 'Test description',
11-
}: {
12-
as?: PolymorphicAs;
13-
children?: ReactNode;
14-
}) => {
15-
return render(<Description as={as}>{children}</Description>);
6+
const renderDescription = (props: React.ComponentProps<typeof Description>) => {
7+
return render(<Description {...props} />);
168
};
179

1810
describe('Description Component', () => {
@@ -37,4 +29,23 @@ describe('Description Component', () => {
3729
});
3830
expect(container.querySelector('div')).toBeInTheDocument();
3931
});
32+
33+
test('renders with a default data-lgid', () => {
34+
const { container } = renderDescription({ children: 'Test description' });
35+
expect(container.querySelector('p')).toHaveAttribute(
36+
'data-lgid',
37+
'lg-typography-description',
38+
);
39+
});
40+
41+
test('renders with a custom data-lgid', () => {
42+
const { container } = renderDescription({
43+
children: 'Test description',
44+
'data-lgid': 'lg-custom-lgid',
45+
});
46+
expect(container.querySelector('p')).toHaveAttribute(
47+
'data-lgid',
48+
'lg-custom-lgid',
49+
);
50+
});
4051
});

packages/typography/src/Description/Description.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ export const Description = Polymorphic<DescriptionProps>(
3333
const as = asProp ?? asDerivedFromChildren;
3434
const { Component } = usePolymorphic(as);
3535

36+
const lgIds = getLgIds(dataLgId ?? getLgIds().description);
37+
3638
return (
3739
<Component
38-
data-lgid={getLgIds(dataLgId).description}
39-
data-testid={getLgIds(dataLgId).description}
40+
data-lgid={lgIds.root}
41+
data-testid={lgIds.root}
4042
className={cx(
4143
getDescriptionStyle(theme),
4244
descriptionTypeScaleStyles[baseFontSize],

packages/typography/src/Label/Label.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ export const Label = Polymorphic<BaseLabelProps>(
3333
const baseFontSize = useUpdatedBaseFontSize(baseFontSizeOverride);
3434
const { Component } = usePolymorphic(as);
3535

36+
const lgIds = getLgIds(dataLgId ?? getLgIds().label);
37+
3638
return (
3739
<Component
38-
data-lgid={getLgIds(dataLgId).label}
39-
data-testid={getLgIds(dataLgId).label}
40+
data-lgid={lgIds.root}
41+
data-testid={lgIds.root}
4042
className={cx(
4143
getLabelStyles(theme),
4244
labelTypeScaleStyles[baseFontSize],

0 commit comments

Comments
 (0)