From d28b30c07bf5e1338eaf9696abd913bc9b2a29c9 Mon Sep 17 00:00:00 2001 From: Chance Strickland Date: Tue, 1 Oct 2024 13:21:57 -0700 Subject: [PATCH] Revert "[Slot] Deduplicate merged `className` prop (#2336)" (#3162) --- .yarn/versions/9bca397e.yml | 3 +++ packages/react/slot/src/Slot.test.tsx | 37 --------------------------- packages/react/slot/src/Slot.tsx | 21 ++------------- 3 files changed, 5 insertions(+), 56 deletions(-) create mode 100644 .yarn/versions/9bca397e.yml diff --git a/.yarn/versions/9bca397e.yml b/.yarn/versions/9bca397e.yml new file mode 100644 index 0000000000..8b0e5a159e --- /dev/null +++ b/.yarn/versions/9bca397e.yml @@ -0,0 +1,3 @@ +declined: + - primitives + - "@radix-ui/react-slot" diff --git a/packages/react/slot/src/Slot.test.tsx b/packages/react/slot/src/Slot.test.tsx index 946787d8e5..c7912b46fe 100644 --- a/packages/react/slot/src/Slot.test.tsx +++ b/packages/react/slot/src/Slot.test.tsx @@ -106,43 +106,6 @@ describe('given a slotted Trigger', () => { expect(handleChildClick).toHaveBeenCalledTimes(1); }); }); - - describe('with className on itself', () => { - beforeEach(() => { - render( - - - - ); - }); - - it('should apply the className to the child', () => { - expect(screen.getByRole('button')).toHaveClass('btn'); - }); - }); - - describe('with className on itself AND the child', () => { - beforeEach(() => { - render( - - - - ); - }); - - it('should merge className and apply it to the child', () => { - expect(screen.getByRole('button')).toHaveClass('btn', 'btn-sm', 'btn-primary'); - }); - - it('should deduplicate merged className', () => { - const classNames = screen.getByRole('button').className.split(' '); - - expect(classNames).toHaveLength(3); - expect(classNames.filter((name) => name === 'btn')).toHaveLength(1); - }); - }); }); describe('given a Button with Slottable', () => { diff --git a/packages/react/slot/src/Slot.tsx b/packages/react/slot/src/Slot.tsx index 655af25caa..c222b1d7f0 100644 --- a/packages/react/slot/src/Slot.tsx +++ b/packages/react/slot/src/Slot.tsx @@ -115,25 +115,8 @@ function mergeProps(slotProps: AnyProps, childProps: AnyProps) { // if it's `style`, we merge them else if (propName === 'style') { overrideProps[propName] = { ...slotPropValue, ...childPropValue }; - } - // if it's `className`, we deduplicate and merge them - else if (propName === 'className') { - const classNameSet = new Set(); - - if (slotPropValue && typeof slotPropValue === 'string') { - slotPropValue - .split(' ') - .filter(Boolean) - .forEach((name) => classNameSet.add(name)); - } - if (childPropValue && typeof childPropValue === 'string') { - childPropValue - .split(' ') - .filter(Boolean) - .forEach((name) => classNameSet.add(name)); - } - - overrideProps[propName] = [...classNameSet].join(' '); + } else if (propName === 'className') { + overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(' '); } }