diff --git a/change/@fluentui-react-aria-4fd3fe1f-3f59-48b1-acab-2e459a62c03d.json b/change/@fluentui-react-aria-4fd3fe1f-3f59-48b1-acab-2e459a62c03d.json new file mode 100644 index 00000000000000..2334b7f180b895 --- /dev/null +++ b/change/@fluentui-react-aria-4fd3fe1f-3f59-48b1-acab-2e459a62c03d.json @@ -0,0 +1,7 @@ +{ + "type": "minor", + "comment": "feat: add helper types to assist DOM element handling", + "packageName": "@fluentui/react-aria", + "email": "bernardo.sunderhus@gmail.com", + "dependentChangeType": "patch" +} diff --git a/packages/react-components/react-aria/etc/react-aria.api.md b/packages/react-components/react-aria/etc/react-aria.api.md index c9f136db5c0509..9450ba46c1e89e 100644 --- a/packages/react-components/react-aria/etc/react-aria.api.md +++ b/packages/react-components/react-aria/etc/react-aria.api.md @@ -9,6 +9,12 @@ import * as React_2 from 'react'; import type { ResolveShorthandFunction } from '@fluentui/react-utilities'; import type { Slot } from '@fluentui/react-utilities'; +// @internal (undocumented) +export type ARIAButtonElement = HTMLButtonElement | (AlternateAs extends 'a' ? HTMLAnchorElement : never) | (AlternateAs extends 'div' ? HTMLDivElement : never); + +// @internal (undocumented) +export type ARIAButtonElementIntersection = UnionToIntersection>; + // @public export type ARIAButtonProps = React_2.PropsWithRef & { disabled?: boolean; diff --git a/packages/react-components/react-aria/src/hooks/useARIAButton/types.ts b/packages/react-components/react-aria/src/hooks/useARIAButton/types.ts index f712dcc341a8d0..541be29d845f9c 100644 --- a/packages/react-components/react-aria/src/hooks/useARIAButton/types.ts +++ b/packages/react-components/react-aria/src/hooks/useARIAButton/types.ts @@ -1,8 +1,25 @@ import type { ExtractSlotProps, Slot } from '@fluentui/react-utilities'; import * as React from 'react'; +type UnionToIntersection = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never; + export type ARIAButtonType = 'button' | 'a' | 'div'; +/** + * @internal + */ +export type ARIAButtonElement = + | HTMLButtonElement + | (AlternateAs extends 'a' ? HTMLAnchorElement : never) + | (AlternateAs extends 'div' ? HTMLDivElement : never); + +/** + * @internal + */ +export type ARIAButtonElementIntersection = UnionToIntersection< + ARIAButtonElement +>; + /** * Props expected by `useARIAButtonProps` hooks */ @@ -48,8 +65,6 @@ export type ARIAButtonAlteredProps = ? Pick : never); -type UnionToIntersection = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never; - /** * Merge of props provided by the user and props provided internally. */ diff --git a/packages/react-components/react-aria/src/index.ts b/packages/react-components/react-aria/src/index.ts index 31983e05e85be0..f5d6693c1789f4 100644 --- a/packages/react-components/react-aria/src/index.ts +++ b/packages/react-components/react-aria/src/index.ts @@ -4,4 +4,6 @@ export type { ARIAButtonProps, ARIAButtonResultProps, ARIAButtonType, + ARIAButtonElement, + ARIAButtonElementIntersection, } from './hooks/useARIAButton/index';