Skip to content

Commit 418846b

Browse files
committed
fix: Clear button context provider on TagGroup items so they dont conflict with parent contexts
1 parent ee060b5 commit 418846b

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

packages/@react-spectrum/s2/src/TagGroup.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
TagGroup as AriaTagGroup,
1818
TagGroupProps as AriaTagGroupProps,
1919
TagProps as AriaTagProps,
20+
ButtonContext as RACButtonContext,
2021
composeRenderProps,
2122
ContextValue,
2223
Provider,
@@ -522,7 +523,10 @@ export const Tag = /*#__PURE__*/ (forwardRef as forwardRefType)(function Tag({ch
522523
function TagWrapper({children, isDisabled, allowsRemoving, isInRealDOM, isEmphasized, isSelected}) {
523524
let {size = 'M'} = useSlottedContext(TagGroupContext) ?? {};
524525
return (
525-
<>
526+
<Provider
527+
values={[
528+
[RACButtonContext, null]
529+
]}>
526530
{isInRealDOM && (
527531
<div
528532
className={style({
@@ -567,6 +571,6 @@ function TagWrapper({children, isDisabled, allowsRemoving, isInRealDOM, isEmphas
567571
isStaticColor={isEmphasized && isSelected}
568572
isDisabled={isDisabled} />
569573
)}
570-
</>
574+
</Provider>
571575
);
572576
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2025 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import {act, pointerMap, render} from '@react-spectrum/test-utils-internal';
14+
import {ActionButton, CustomDialog, DialogTrigger, Tag, TagGroup} from '../src';
15+
import React from 'react';
16+
import userEvent from '@testing-library/user-event';
17+
18+
describe('CustomDialog', () => {
19+
let user;
20+
beforeAll(() => {
21+
user = userEvent.setup({delay: null, pointerMap});
22+
jest.useFakeTimers();
23+
});
24+
25+
afterEach(() => {
26+
jest.clearAllMocks();
27+
act(() => jest.runAllTimers());
28+
});
29+
30+
afterAll(function () {
31+
jest.restoreAllMocks();
32+
});
33+
34+
it('should allow you to render a taggroup inside', async () => {
35+
let {getByRole} = render(
36+
<DialogTrigger>
37+
<ActionButton>Open dialog</ActionButton>
38+
<CustomDialog isDismissible>
39+
<TagGroup
40+
label="Ice cream categories"
41+
maxRows={1}
42+
onRemove={() => {}}>
43+
<Tag>Chocolate</Tag>
44+
<Tag>Mint</Tag>
45+
<Tag>Strawberry</Tag>
46+
<Tag>Vanilla</Tag>
47+
</TagGroup>
48+
</CustomDialog>
49+
</DialogTrigger>
50+
);
51+
52+
53+
let trigger = getByRole('button');
54+
await user.click(trigger);
55+
act(() => {jest.runAllTimers();});
56+
57+
expect(getByRole('dialog')).toBeVisible();
58+
});
59+
});

0 commit comments

Comments
 (0)