Skip to content

Commit 6829f06

Browse files
authored
fix: apply hover state on Tags with href (adobe#9750)
* bring back hasAction state in TagAria * fix Tag with action being disabled on hover * add new unit test for hover on Tag with href
1 parent ee49fdb commit 6829f06

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

packages/@react-aria/tag/src/useTag.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {useGridListItem} from '@react-aria/gridlist';
2424
import {useLocalizedStringFormatter} from '@react-aria/i18n';
2525

2626

27-
export interface TagAria extends Omit<SelectableItemStates, 'hasAction'> {
27+
export interface TagAria extends SelectableItemStates {
2828
/** Props for the tag row element. */
2929
rowProps: DOMAttributes,
3030
/** Props for the tag cell element. */

packages/react-aria-components/src/TagGroup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export const Tag = /*#__PURE__*/ createLeafComponent(ItemNode, (props: TagProps,
249249
let {rowProps, gridCellProps, removeButtonProps, ...states} = useTag({item}, state, ref);
250250

251251
let {hoverProps, isHovered} = useHover({
252-
isDisabled: !states.allowsSelection,
252+
isDisabled: !states.allowsSelection && !states.hasAction,
253253
onHoverStart: item.props.onHoverStart,
254254
onHoverChange: item.props.onHoverChange,
255255
onHoverEnd: item.props.onHoverEnd

packages/react-aria-components/test/TagGroup.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,29 @@ describe('TagGroup', () => {
176176
expect(onHoverEnd).not.toHaveBeenCalled();
177177
});
178178

179+
it('should show hover state when tag has an href even without selectionMode', async () => {
180+
let onHoverStart = jest.fn();
181+
let onHoverChange = jest.fn();
182+
let onHoverEnd = jest.fn();
183+
let {getAllByRole} = renderTagGroup({}, {}, {href: '/', className: ({isHovered}) => isHovered ? 'hover' : '', onHoverStart, onHoverChange, onHoverEnd});
184+
let row = getAllByRole('row')[0];
185+
186+
expect(row).not.toHaveAttribute('data-hovered');
187+
expect(row).not.toHaveClass('hover');
188+
189+
await user.hover(row);
190+
expect(row).toHaveAttribute('data-hovered', 'true');
191+
expect(row).toHaveClass('hover');
192+
expect(onHoverStart).toHaveBeenCalledTimes(1);
193+
expect(onHoverChange).toHaveBeenCalledTimes(1);
194+
195+
await user.unhover(row);
196+
expect(row).not.toHaveAttribute('data-hovered');
197+
expect(row).not.toHaveClass('hover');
198+
expect(onHoverEnd).toHaveBeenCalledTimes(1);
199+
expect(onHoverChange).toHaveBeenCalledTimes(2);
200+
});
201+
179202
it('should support focus ring', async () => {
180203
let onFocus = jest.fn();
181204
let onFocusChange = jest.fn();

0 commit comments

Comments
 (0)