From 54cd898c8d505c0cb7f35489cf6fef7de9048d94 Mon Sep 17 00:00:00 2001 From: Reid Barber Date: Mon, 13 Feb 2023 13:49:09 -0600 Subject: [PATCH] move useTag ref from props to param --- packages/@react-aria/tag/src/useTag.ts | 11 +++++------ packages/@react-spectrum/tag/src/Tag.tsx | 9 ++++----- packages/@react-types/tag/src/index.d.ts | 5 ++--- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/packages/@react-aria/tag/src/useTag.ts b/packages/@react-aria/tag/src/useTag.ts index a3b1610d751..58d1e579998 100644 --- a/packages/@react-aria/tag/src/useTag.ts +++ b/packages/@react-aria/tag/src/useTag.ts @@ -12,10 +12,10 @@ import {AriaButtonProps} from '@react-types/button'; import {chain, filterDOMProps, mergeProps, useId} from '@react-aria/utils'; -import {DOMAttributes} from '@react-types/shared'; +import {DOMAttributes, FocusableElement} from '@react-types/shared'; // @ts-ignore import intlMessages from '../intl/*.json'; -import {KeyboardEvent} from 'react'; +import {KeyboardEvent, RefObject} from 'react'; import type {TagGroupState} from '@react-stately/tag'; import {TagProps} from '@react-types/tag'; import {useGridListItem} from '@react-aria/gridlist'; @@ -34,12 +34,11 @@ export interface TagAria { * @param props - Props to be applied to the tag. * @param state - State for the tag group, as returned by `useTagGroupState`. */ -export function useTag(props: TagProps, state: TagGroupState): TagAria { +export function useTag(props: TagProps, state: TagGroupState, ref: RefObject): TagAria { let { isFocused, allowsRemoving, - item, - tagRowRef + item } = props; let stringFormatter = useLocalizedStringFormatter(intlMessages); let removeString = stringFormatter.format('remove'); @@ -48,7 +47,7 @@ export function useTag(props: TagProps, state: TagGroupState): TagAria let {rowProps, gridCellProps} = useGridListItem({ node: item - }, state, tagRowRef); + }, state, ref); // We want the group to handle keyboard navigation between tags. delete rowProps.onKeyDownCapture; diff --git a/packages/@react-spectrum/tag/src/Tag.tsx b/packages/@react-spectrum/tag/src/Tag.tsx index f02c1106455..ff654b4de12 100644 --- a/packages/@react-spectrum/tag/src/Tag.tsx +++ b/packages/@react-spectrum/tag/src/Tag.tsx @@ -40,15 +40,14 @@ export function Tag(props: SpectrumTagProps) { let {styleProps} = useStyleProps(otherProps); let {hoverProps, isHovered} = useHover({}); let {isFocused, isFocusVisible, focusProps} = useFocusRing({within: true}); - let tagRowRef = useRef(); + let ref = useRef(); let {clearButtonProps, labelProps, tagProps, tagRowProps} = useTag({ ...props, isFocused, allowsRemoving, item, - onRemove, - tagRowRef - }, state); + onRemove + }, state, ref); return (
(props: SpectrumTagProps) { }, styleProps.className )} - ref={tagRowRef}> + ref={ref}>
diff --git a/packages/@react-types/tag/src/index.d.ts b/packages/@react-types/tag/src/index.d.ts index 3632f49c130..2e3c8cf4999 100644 --- a/packages/@react-types/tag/src/index.d.ts +++ b/packages/@react-types/tag/src/index.d.ts @@ -11,7 +11,7 @@ */ import {CollectionBase, ItemProps, Node} from '@react-types/shared'; -import {Key, RefObject} from 'react'; +import {Key} from 'react'; export interface TagGroupProps extends Omit, 'disabledKeys'> { /** Whether the TagGroup allows removal of tags. */ @@ -26,6 +26,5 @@ export interface TagProps extends ItemProps { isFocused: boolean, allowsRemoving?: boolean, item: Node, - onRemove?: (key: Key) => void, - tagRowRef: RefObject + onRemove?: (key: Key) => void }