|
13 | 13 | import {Button, Label, RouterProvider, Tag, TagGroup, TagList, Text} from '../';
|
14 | 14 | import {fireEvent, mockClickDefault, pointerMap, render} from '@react-spectrum/test-utils-internal';
|
15 | 15 | import React from 'react';
|
| 16 | +import {useListData} from '@react-stately/data'; |
16 | 17 | import userEvent from '@testing-library/user-event';
|
17 | 18 |
|
18 | 19 | let TestTagGroup = ({tagGroupProps, tagListProps, itemProps}) => (
|
@@ -351,4 +352,45 @@ describe('TagGroup', () => {
|
351 | 352 | });
|
352 | 353 | });
|
353 | 354 | });
|
| 355 | + it('if we cannot restore focus to next, then restore to previous but do not try focusing next again', async () => { |
| 356 | + function MyTagGroup(props) { |
| 357 | + const fruitsList = useListData({ |
| 358 | + initialItems: [ |
| 359 | + {id: 2, name: 'Grape'}, |
| 360 | + {id: 3, name: 'Plum'}, |
| 361 | + {id: 4, name: 'Watermelon'} |
| 362 | + ] |
| 363 | + }); |
| 364 | + return ( |
| 365 | + <TagGroup |
| 366 | + data-testid="group" |
| 367 | + aria-label="Fruits" |
| 368 | + items={fruitsList.items} |
| 369 | + selectionMode="multiple" |
| 370 | + disabledKeys={[2, 3]} |
| 371 | + onRemove={(keys) => fruitsList.remove(...keys)}> |
| 372 | + <TagList items={fruitsList.items}> |
| 373 | + {(item) => <MyTag item={item}>{item.name}</MyTag>} |
| 374 | + </TagList> |
| 375 | + </TagGroup> |
| 376 | + ); |
| 377 | + } |
| 378 | + function MyTag({children, item, ...props}) { |
| 379 | + return ( |
| 380 | + <Tag textValue={item.name} {...props}> |
| 381 | + {({isDisabled}) => ( |
| 382 | + <> |
| 383 | + {children} |
| 384 | + <Button slot="remove" isDisabled={isDisabled} aria-label={'remove'} /> |
| 385 | + </> |
| 386 | + )} |
| 387 | + </Tag> |
| 388 | + ); |
| 389 | + } |
| 390 | + let {getByRole} = render(<MyTagGroup />); |
| 391 | + let grid = getByRole('grid'); |
| 392 | + await user.tab(); |
| 393 | + await user.keyboard('{Backspace}'); |
| 394 | + expect(grid).toHaveFocus(); |
| 395 | + }); |
354 | 396 | });
|
0 commit comments