Skip to content

Commit cfade8a

Browse files
fralongoFrancesco Longo
andauthored
fix: Analytics label for icon buttons with children (#3559)
Co-authored-by: Francesco Longo <[email protected]>
1 parent 61d08fb commit cfade8a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/button/__tests__/analytics-metadata.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ describe('Button renders correct analytics metadata', () => {
7575
validateComponentNameAndLabels(wrapper.getElement(), labels);
7676
expect(getGeneratedAnalyticsMetadata(wrapper.getElement())).toEqual(getMetadata('button text aria', 'inline-icon'));
7777
});
78+
test('when it has icon variant and children', () => {
79+
const wrapper = renderButton({
80+
ariaLabel: 'button text aria',
81+
variant: 'inline-icon',
82+
children: 'invisible but there',
83+
});
84+
validateComponentNameAndLabels(wrapper.getElement(), labels);
85+
expect(getGeneratedAnalyticsMetadata(wrapper.getElement())).toEqual(getMetadata('button text aria', 'inline-icon'));
86+
});
7887
});
7988
describe('Internal Button', () => {
8089
test('does not render "component" metadata', () => {

src/button/internal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export const InternalButton = React.forwardRef(
222222
onClick: handleClick,
223223
[DATA_ATTR_FUNNEL_VALUE]: uniqueId,
224224
...getAnalyticsMetadataAttribute(analyticsMetadata),
225-
...getAnalyticsLabelAttribute(children ? `.${analyticsSelectors.label}` : ''),
225+
...getAnalyticsLabelAttribute(shouldHaveContent ? `.${analyticsSelectors.label}` : ''),
226226
} as const;
227227

228228
const iconProps: ButtonIconProps = {

0 commit comments

Comments
 (0)