@react-aria/link 3.5.4 → 3.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/import.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import {filterDOMProps as $kKV4x$filterDOMProps, mergeProps as $kKV4x$mergeProps} from "@react-aria/utils";
1
+ import {filterDOMProps as $kKV4x$filterDOMProps, mergeProps as $kKV4x$mergeProps, useRouter as $kKV4x$useRouter, shouldClientNavigate as $kKV4x$shouldClientNavigate} from "@react-aria/utils";
2
2
  import {useFocusable as $kKV4x$useFocusable} from "@react-aria/focus";
3
3
  import {usePress as $kKV4x$usePress} from "@react-aria/interactions";
4
4
 
@@ -26,15 +26,15 @@ import {usePress as $kKV4x$usePress} from "@react-aria/interactions";
26
26
 
27
27
 
28
28
  function $298d61e98472621b$export$dcf14c9974fe2767(props, ref) {
29
- let { elementType: elementType = "a" , onPress: onPress , onPressStart: onPressStart , onPressEnd: onPressEnd , // @ts-ignore
30
- onClick: deprecatedOnClick , isDisabled: isDisabled , ...otherProps } = props;
29
+ let { elementType: elementType = "a", onPress: onPress, onPressStart: onPressStart, onPressEnd: onPressEnd, // @ts-ignore
30
+ onClick: deprecatedOnClick, isDisabled: isDisabled, ...otherProps } = props;
31
31
  let linkProps = {};
32
32
  if (elementType !== "a") linkProps = {
33
33
  role: "link",
34
34
  tabIndex: !isDisabled ? 0 : undefined
35
35
  };
36
- let { focusableProps: focusableProps } = (0, $kKV4x$useFocusable)(props, ref);
37
- let { pressProps: pressProps , isPressed: isPressed } = (0, $kKV4x$usePress)({
36
+ let { focusableProps: focusableProps } = (0, $kKV4x$useFocusable)(props, ref);
37
+ let { pressProps: pressProps, isPressed: isPressed } = (0, $kKV4x$usePress)({
38
38
  onPress: onPress,
39
39
  onPressStart: onPressStart,
40
40
  onPressEnd: onPressEnd,
@@ -42,9 +42,11 @@ function $298d61e98472621b$export$dcf14c9974fe2767(props, ref) {
42
42
  ref: ref
43
43
  });
44
44
  let domProps = (0, $kKV4x$filterDOMProps)(otherProps, {
45
- labelable: true
45
+ labelable: true,
46
+ isLink: elementType === "a"
46
47
  });
47
48
  let interactionHandlers = (0, $kKV4x$mergeProps)(focusableProps, pressProps);
49
+ let router = (0, $kKV4x$useRouter)();
48
50
  return {
49
51
  isPressed: isPressed,
50
52
  linkProps: (0, $kKV4x$mergeProps)(domProps, {
@@ -59,6 +61,12 @@ function $298d61e98472621b$export$dcf14c9974fe2767(props, ref) {
59
61
  deprecatedOnClick(e);
60
62
  console.warn("onClick is deprecated, please use onPress");
61
63
  }
64
+ // If a custom router is provided, prevent default and forward if this link should client navigate.
65
+ if (!router.isNative && e.currentTarget instanceof HTMLAnchorElement && e.currentTarget.href && // If props are applied to a router Link component, it may have already prevented default.
66
+ !e.isDefaultPrevented() && (0, $kKV4x$shouldClientNavigate)(e.currentTarget, e)) {
67
+ e.preventDefault();
68
+ router.open(e.currentTarget, e);
69
+ }
62
70
  }
63
71
  })
64
72
  };
package/dist/main.js CHANGED
@@ -31,15 +31,15 @@ $parcel$export(module.exports, "useLink", () => $fbe6b19572273b2f$export$dcf14c9
31
31
 
32
32
 
33
33
  function $fbe6b19572273b2f$export$dcf14c9974fe2767(props, ref) {
34
- let { elementType: elementType = "a" , onPress: onPress , onPressStart: onPressStart , onPressEnd: onPressEnd , // @ts-ignore
35
- onClick: deprecatedOnClick , isDisabled: isDisabled , ...otherProps } = props;
34
+ let { elementType: elementType = "a", onPress: onPress, onPressStart: onPressStart, onPressEnd: onPressEnd, // @ts-ignore
35
+ onClick: deprecatedOnClick, isDisabled: isDisabled, ...otherProps } = props;
36
36
  let linkProps = {};
37
37
  if (elementType !== "a") linkProps = {
38
38
  role: "link",
39
39
  tabIndex: !isDisabled ? 0 : undefined
40
40
  };
41
- let { focusableProps: focusableProps } = (0, $3NNeN$reactariafocus.useFocusable)(props, ref);
42
- let { pressProps: pressProps , isPressed: isPressed } = (0, $3NNeN$reactariainteractions.usePress)({
41
+ let { focusableProps: focusableProps } = (0, $3NNeN$reactariafocus.useFocusable)(props, ref);
42
+ let { pressProps: pressProps, isPressed: isPressed } = (0, $3NNeN$reactariainteractions.usePress)({
43
43
  onPress: onPress,
44
44
  onPressStart: onPressStart,
45
45
  onPressEnd: onPressEnd,
@@ -47,9 +47,11 @@ function $fbe6b19572273b2f$export$dcf14c9974fe2767(props, ref) {
47
47
  ref: ref
48
48
  });
49
49
  let domProps = (0, $3NNeN$reactariautils.filterDOMProps)(otherProps, {
50
- labelable: true
50
+ labelable: true,
51
+ isLink: elementType === "a"
51
52
  });
52
53
  let interactionHandlers = (0, $3NNeN$reactariautils.mergeProps)(focusableProps, pressProps);
54
+ let router = (0, $3NNeN$reactariautils.useRouter)();
53
55
  return {
54
56
  isPressed: isPressed,
55
57
  linkProps: (0, $3NNeN$reactariautils.mergeProps)(domProps, {
@@ -64,6 +66,12 @@ function $fbe6b19572273b2f$export$dcf14c9974fe2767(props, ref) {
64
66
  deprecatedOnClick(e);
65
67
  console.warn("onClick is deprecated, please use onPress");
66
68
  }
69
+ // If a custom router is provided, prevent default and forward if this link should client navigate.
70
+ if (!router.isNative && e.currentTarget instanceof HTMLAnchorElement && e.currentTarget.href && // If props are applied to a router Link component, it may have already prevented default.
71
+ !e.isDefaultPrevented() && (0, $3NNeN$reactariautils.shouldClientNavigate)(e.currentTarget, e)) {
72
+ e.preventDefault();
73
+ router.open(e.currentTarget, e);
74
+ }
67
75
  }
68
76
  })
69
77
  };
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;AA+BM,SAAS,0CAAQ,KAAsB,EAAE,GAAgC;IAC9E,IAAI,eACF,cAAc,eACd,QAAO,gBACP,aAAY,cACZ,WAAU,EACV,aAAa;IACb,SAAS,kBAAiB,cAC1B,WAAU,EACV,GAAG,YACJ,GAAG;IAEJ,IAAI,YAA2B,CAAC;IAChC,IAAI,gBAAgB,KAClB,YAAY;QACV,MAAM;QACN,UAAU,CAAC,aAAa,IAAI;IAC9B;IAEF,IAAI,kBAAC,eAAc,EAAC,GAAG,CAAA,GAAA,kCAAW,EAAE,OAAO;IAC3C,IAAI,cAAC,WAAU,aAAE,UAAS,EAAC,GAAG,CAAA,GAAA,qCAAO,EAAE;iBAAC;sBAAS;oBAAc;oBAAY;aAAY;IAAG;IAC1F,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE,YAAY;QAAC,WAAW;IAAI;IAC1D,IAAI,sBAAsB,CAAA,GAAA,gCAAS,EAAE,gBAAgB;IAErD,OAAO;mBACL;QACA,WAAW,CAAA,GAAA,gCAAS,EAAE,UAAU;YAC9B,GAAG,mBAAmB;YACtB,GAAG,SAAS;YACZ,iBAAiB,cAAc;YAC/B,gBAAgB,KAAK,CAAC,eAAe;YACrC,SAAS,CAAC;oBACR;gBAAA,CAAA,sBAAA,WAAW,qBAAX,iCAAA,KAAA,IAAA,oBAAA,KAAA,YAAqB;gBACrB,IAAI,mBAAmB;oBACrB,kBAAkB;oBAClB,QAAQ,KAAK;gBACf;YACF;QACF;IACF;AACF;;CDvEC","sources":["packages/@react-aria/link/src/index.ts","packages/@react-aria/link/src/useLink.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport type {AriaLinkOptions, LinkAria} from './useLink';\nexport {useLink} from './useLink';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLinkProps} from '@react-types/link';\nimport {DOMAttributes, FocusableElement} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {RefObject} from 'react';\nimport {useFocusable} from '@react-aria/focus';\nimport {usePress} from '@react-aria/interactions';\n\nexport interface AriaLinkOptions extends AriaLinkProps {\n /** Whether the link is disabled. */\n isDisabled?: boolean,\n /**\n * The HTML element used to render the link, e.g. 'a', or 'span'.\n * @default 'a'\n */\n elementType?: string\n}\n\nexport interface LinkAria {\n /** Props for the link element. */\n linkProps: DOMAttributes,\n /** Whether the link is currently pressed. */\n isPressed: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for a link component.\n * A link allows a user to navigate to another page or resource within a web page\n * or application.\n */\nexport function useLink(props: AriaLinkOptions, ref: RefObject<FocusableElement>): LinkAria {\n let {\n elementType = 'a',\n onPress,\n onPressStart,\n onPressEnd,\n // @ts-ignore\n onClick: deprecatedOnClick,\n isDisabled,\n ...otherProps\n } = props;\n\n let linkProps: DOMAttributes = {};\n if (elementType !== 'a') {\n linkProps = {\n role: 'link',\n tabIndex: !isDisabled ? 0 : undefined\n };\n }\n let {focusableProps} = useFocusable(props, ref);\n let {pressProps, isPressed} = usePress({onPress, onPressStart, onPressEnd, isDisabled, ref});\n let domProps = filterDOMProps(otherProps, {labelable: true});\n let interactionHandlers = mergeProps(focusableProps, pressProps);\n\n return {\n isPressed, // Used to indicate press state for visual\n linkProps: mergeProps(domProps, {\n ...interactionHandlers,\n ...linkProps,\n 'aria-disabled': isDisabled || undefined,\n 'aria-current': props['aria-current'],\n onClick: (e) => {\n pressProps.onClick?.(e);\n if (deprecatedOnClick) {\n deprecatedOnClick(e);\n console.warn('onClick is deprecated, please use onPress');\n }\n }\n })\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;AA+BM,SAAS,0CAAQ,KAAsB,EAAE,GAAgC;IAC9E,IAAI,eACF,cAAc,cACd,OAAO,gBACP,YAAY,cACZ,UAAU,EACV,aAAa;IACb,SAAS,iBAAiB,cAC1B,UAAU,EACV,GAAG,YACJ,GAAG;IAEJ,IAAI,YAA2B,CAAC;IAChC,IAAI,gBAAgB,KAClB,YAAY;QACV,MAAM;QACN,UAAU,CAAC,aAAa,IAAI;IAC9B;IAEF,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,kCAAW,EAAE,OAAO;IAC3C,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,qCAAO,EAAE;iBAAC;sBAAS;oBAAc;oBAAY;aAAY;IAAG;IAC1F,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE,YAAY;QAAC,WAAW;QAAM,QAAQ,gBAAgB;IAAG;IACvF,IAAI,sBAAsB,CAAA,GAAA,gCAAS,EAAE,gBAAgB;IACrD,IAAI,SAAS,CAAA,GAAA,+BAAQ;IAErB,OAAO;mBACL;QACA,WAAW,CAAA,GAAA,gCAAS,EAAE,UAAU;YAC9B,GAAG,mBAAmB;YACtB,GAAG,SAAS;YACZ,iBAAiB,cAAc;YAC/B,gBAAgB,KAAK,CAAC,eAAe;YACrC,SAAS,CAAC;oBACR;gBAAA,CAAA,sBAAA,WAAW,qBAAX,iCAAA,KAAA,IAAA,oBAAA,KAAA,YAAqB;gBACrB,IAAI,mBAAmB;oBACrB,kBAAkB;oBAClB,QAAQ,KAAK;gBACf;gBAEA,mGAAmG;gBACnG,IACE,CAAC,OAAO,YACR,EAAE,yBAAyB,qBAC3B,EAAE,cAAc,QAChB,0FAA0F;gBAC1F,CAAC,EAAE,wBACH,CAAA,GAAA,0CAAmB,EAAE,EAAE,eAAe,IACtC;oBACA,EAAE;oBACF,OAAO,KAAK,EAAE,eAAe;gBAC/B;YACF;QACF;IACF;AACF;;CDrFC","sources":["packages/@react-aria/link/src/index.ts","packages/@react-aria/link/src/useLink.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport type {AriaLinkOptions, LinkAria} from './useLink';\nexport {useLink} from './useLink';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLinkProps} from '@react-types/link';\nimport {DOMAttributes, FocusableElement} from '@react-types/shared';\nimport {filterDOMProps, mergeProps, shouldClientNavigate, useRouter} from '@react-aria/utils';\nimport React, {RefObject} from 'react';\nimport {useFocusable} from '@react-aria/focus';\nimport {usePress} from '@react-aria/interactions';\n\nexport interface AriaLinkOptions extends AriaLinkProps {\n /** Whether the link is disabled. */\n isDisabled?: boolean,\n /**\n * The HTML element used to render the link, e.g. 'a', or 'span'.\n * @default 'a'\n */\n elementType?: string\n}\n\nexport interface LinkAria {\n /** Props for the link element. */\n linkProps: DOMAttributes,\n /** Whether the link is currently pressed. */\n isPressed: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for a link component.\n * A link allows a user to navigate to another page or resource within a web page\n * or application.\n */\nexport function useLink(props: AriaLinkOptions, ref: RefObject<FocusableElement>): LinkAria {\n let {\n elementType = 'a',\n onPress,\n onPressStart,\n onPressEnd,\n // @ts-ignore\n onClick: deprecatedOnClick,\n isDisabled,\n ...otherProps\n } = props;\n\n let linkProps: DOMAttributes = {};\n if (elementType !== 'a') {\n linkProps = {\n role: 'link',\n tabIndex: !isDisabled ? 0 : undefined\n };\n }\n let {focusableProps} = useFocusable(props, ref);\n let {pressProps, isPressed} = usePress({onPress, onPressStart, onPressEnd, isDisabled, ref});\n let domProps = filterDOMProps(otherProps, {labelable: true, isLink: elementType === 'a'});\n let interactionHandlers = mergeProps(focusableProps, pressProps);\n let router = useRouter();\n\n return {\n isPressed, // Used to indicate press state for visual\n linkProps: mergeProps(domProps, {\n ...interactionHandlers,\n ...linkProps,\n 'aria-disabled': isDisabled || undefined,\n 'aria-current': props['aria-current'],\n onClick: (e: React.MouseEvent<HTMLAnchorElement>) => {\n pressProps.onClick?.(e);\n if (deprecatedOnClick) {\n deprecatedOnClick(e);\n console.warn('onClick is deprecated, please use onPress');\n }\n\n // If a custom router is provided, prevent default and forward if this link should client navigate.\n if (\n !router.isNative &&\n e.currentTarget instanceof HTMLAnchorElement &&\n e.currentTarget.href &&\n // If props are applied to a router Link component, it may have already prevented default.\n !e.isDefaultPrevented() &&\n shouldClientNavigate(e.currentTarget, e)\n ) {\n e.preventDefault();\n router.open(e.currentTarget, e);\n }\n }\n })\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,4 +1,4 @@
1
- import {filterDOMProps as $kKV4x$filterDOMProps, mergeProps as $kKV4x$mergeProps} from "@react-aria/utils";
1
+ import {filterDOMProps as $kKV4x$filterDOMProps, mergeProps as $kKV4x$mergeProps, useRouter as $kKV4x$useRouter, shouldClientNavigate as $kKV4x$shouldClientNavigate} from "@react-aria/utils";
2
2
  import {useFocusable as $kKV4x$useFocusable} from "@react-aria/focus";
3
3
  import {usePress as $kKV4x$usePress} from "@react-aria/interactions";
4
4
 
@@ -26,15 +26,15 @@ import {usePress as $kKV4x$usePress} from "@react-aria/interactions";
26
26
 
27
27
 
28
28
  function $298d61e98472621b$export$dcf14c9974fe2767(props, ref) {
29
- let { elementType: elementType = "a" , onPress: onPress , onPressStart: onPressStart , onPressEnd: onPressEnd , // @ts-ignore
30
- onClick: deprecatedOnClick , isDisabled: isDisabled , ...otherProps } = props;
29
+ let { elementType: elementType = "a", onPress: onPress, onPressStart: onPressStart, onPressEnd: onPressEnd, // @ts-ignore
30
+ onClick: deprecatedOnClick, isDisabled: isDisabled, ...otherProps } = props;
31
31
  let linkProps = {};
32
32
  if (elementType !== "a") linkProps = {
33
33
  role: "link",
34
34
  tabIndex: !isDisabled ? 0 : undefined
35
35
  };
36
- let { focusableProps: focusableProps } = (0, $kKV4x$useFocusable)(props, ref);
37
- let { pressProps: pressProps , isPressed: isPressed } = (0, $kKV4x$usePress)({
36
+ let { focusableProps: focusableProps } = (0, $kKV4x$useFocusable)(props, ref);
37
+ let { pressProps: pressProps, isPressed: isPressed } = (0, $kKV4x$usePress)({
38
38
  onPress: onPress,
39
39
  onPressStart: onPressStart,
40
40
  onPressEnd: onPressEnd,
@@ -42,9 +42,11 @@ function $298d61e98472621b$export$dcf14c9974fe2767(props, ref) {
42
42
  ref: ref
43
43
  });
44
44
  let domProps = (0, $kKV4x$filterDOMProps)(otherProps, {
45
- labelable: true
45
+ labelable: true,
46
+ isLink: elementType === "a"
46
47
  });
47
48
  let interactionHandlers = (0, $kKV4x$mergeProps)(focusableProps, pressProps);
49
+ let router = (0, $kKV4x$useRouter)();
48
50
  return {
49
51
  isPressed: isPressed,
50
52
  linkProps: (0, $kKV4x$mergeProps)(domProps, {
@@ -59,6 +61,12 @@ function $298d61e98472621b$export$dcf14c9974fe2767(props, ref) {
59
61
  deprecatedOnClick(e);
60
62
  console.warn("onClick is deprecated, please use onPress");
61
63
  }
64
+ // If a custom router is provided, prevent default and forward if this link should client navigate.
65
+ if (!router.isNative && e.currentTarget instanceof HTMLAnchorElement && e.currentTarget.href && // If props are applied to a router Link component, it may have already prevented default.
66
+ !e.isDefaultPrevented() && (0, $kKV4x$shouldClientNavigate)(e.currentTarget, e)) {
67
+ e.preventDefault();
68
+ router.open(e.currentTarget, e);
69
+ }
62
70
  }
63
71
  })
64
72
  };
@@ -1 +1 @@
1
- {"mappings":";;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;AA+BM,SAAS,0CAAQ,KAAsB,EAAE,GAAgC;IAC9E,IAAI,eACF,cAAc,eACd,QAAO,gBACP,aAAY,cACZ,WAAU,EACV,aAAa;IACb,SAAS,kBAAiB,cAC1B,WAAU,EACV,GAAG,YACJ,GAAG;IAEJ,IAAI,YAA2B,CAAC;IAChC,IAAI,gBAAgB,KAClB,YAAY;QACV,MAAM;QACN,UAAU,CAAC,aAAa,IAAI;IAC9B;IAEF,IAAI,kBAAC,eAAc,EAAC,GAAG,CAAA,GAAA,mBAAW,EAAE,OAAO;IAC3C,IAAI,cAAC,WAAU,aAAE,UAAS,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;iBAAC;sBAAS;oBAAc;oBAAY;aAAY;IAAG;IAC1F,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE,YAAY;QAAC,WAAW;IAAI;IAC1D,IAAI,sBAAsB,CAAA,GAAA,iBAAS,EAAE,gBAAgB;IAErD,OAAO;mBACL;QACA,WAAW,CAAA,GAAA,iBAAS,EAAE,UAAU;YAC9B,GAAG,mBAAmB;YACtB,GAAG,SAAS;YACZ,iBAAiB,cAAc;YAC/B,gBAAgB,KAAK,CAAC,eAAe;YACrC,SAAS,CAAC;oBACR;gBAAA,CAAA,sBAAA,WAAW,qBAAX,iCAAA,KAAA,IAAA,oBAAA,KAAA,YAAqB;gBACrB,IAAI,mBAAmB;oBACrB,kBAAkB;oBAClB,QAAQ,KAAK;gBACf;YACF;QACF;IACF;AACF;;CDvEC","sources":["packages/@react-aria/link/src/index.ts","packages/@react-aria/link/src/useLink.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport type {AriaLinkOptions, LinkAria} from './useLink';\nexport {useLink} from './useLink';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLinkProps} from '@react-types/link';\nimport {DOMAttributes, FocusableElement} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {RefObject} from 'react';\nimport {useFocusable} from '@react-aria/focus';\nimport {usePress} from '@react-aria/interactions';\n\nexport interface AriaLinkOptions extends AriaLinkProps {\n /** Whether the link is disabled. */\n isDisabled?: boolean,\n /**\n * The HTML element used to render the link, e.g. 'a', or 'span'.\n * @default 'a'\n */\n elementType?: string\n}\n\nexport interface LinkAria {\n /** Props for the link element. */\n linkProps: DOMAttributes,\n /** Whether the link is currently pressed. */\n isPressed: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for a link component.\n * A link allows a user to navigate to another page or resource within a web page\n * or application.\n */\nexport function useLink(props: AriaLinkOptions, ref: RefObject<FocusableElement>): LinkAria {\n let {\n elementType = 'a',\n onPress,\n onPressStart,\n onPressEnd,\n // @ts-ignore\n onClick: deprecatedOnClick,\n isDisabled,\n ...otherProps\n } = props;\n\n let linkProps: DOMAttributes = {};\n if (elementType !== 'a') {\n linkProps = {\n role: 'link',\n tabIndex: !isDisabled ? 0 : undefined\n };\n }\n let {focusableProps} = useFocusable(props, ref);\n let {pressProps, isPressed} = usePress({onPress, onPressStart, onPressEnd, isDisabled, ref});\n let domProps = filterDOMProps(otherProps, {labelable: true});\n let interactionHandlers = mergeProps(focusableProps, pressProps);\n\n return {\n isPressed, // Used to indicate press state for visual\n linkProps: mergeProps(domProps, {\n ...interactionHandlers,\n ...linkProps,\n 'aria-disabled': isDisabled || undefined,\n 'aria-current': props['aria-current'],\n onClick: (e) => {\n pressProps.onClick?.(e);\n if (deprecatedOnClick) {\n deprecatedOnClick(e);\n console.warn('onClick is deprecated, please use onPress');\n }\n }\n })\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;AA+BM,SAAS,0CAAQ,KAAsB,EAAE,GAAgC;IAC9E,IAAI,eACF,cAAc,cACd,OAAO,gBACP,YAAY,cACZ,UAAU,EACV,aAAa;IACb,SAAS,iBAAiB,cAC1B,UAAU,EACV,GAAG,YACJ,GAAG;IAEJ,IAAI,YAA2B,CAAC;IAChC,IAAI,gBAAgB,KAClB,YAAY;QACV,MAAM;QACN,UAAU,CAAC,aAAa,IAAI;IAC9B;IAEF,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,mBAAW,EAAE,OAAO;IAC3C,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;iBAAC;sBAAS;oBAAc;oBAAY;aAAY;IAAG;IAC1F,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE,YAAY;QAAC,WAAW;QAAM,QAAQ,gBAAgB;IAAG;IACvF,IAAI,sBAAsB,CAAA,GAAA,iBAAS,EAAE,gBAAgB;IACrD,IAAI,SAAS,CAAA,GAAA,gBAAQ;IAErB,OAAO;mBACL;QACA,WAAW,CAAA,GAAA,iBAAS,EAAE,UAAU;YAC9B,GAAG,mBAAmB;YACtB,GAAG,SAAS;YACZ,iBAAiB,cAAc;YAC/B,gBAAgB,KAAK,CAAC,eAAe;YACrC,SAAS,CAAC;oBACR;gBAAA,CAAA,sBAAA,WAAW,qBAAX,iCAAA,KAAA,IAAA,oBAAA,KAAA,YAAqB;gBACrB,IAAI,mBAAmB;oBACrB,kBAAkB;oBAClB,QAAQ,KAAK;gBACf;gBAEA,mGAAmG;gBACnG,IACE,CAAC,OAAO,YACR,EAAE,yBAAyB,qBAC3B,EAAE,cAAc,QAChB,0FAA0F;gBAC1F,CAAC,EAAE,wBACH,CAAA,GAAA,2BAAmB,EAAE,EAAE,eAAe,IACtC;oBACA,EAAE;oBACF,OAAO,KAAK,EAAE,eAAe;gBAC/B;YACF;QACF;IACF;AACF;;CDrFC","sources":["packages/@react-aria/link/src/index.ts","packages/@react-aria/link/src/useLink.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport type {AriaLinkOptions, LinkAria} from './useLink';\nexport {useLink} from './useLink';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLinkProps} from '@react-types/link';\nimport {DOMAttributes, FocusableElement} from '@react-types/shared';\nimport {filterDOMProps, mergeProps, shouldClientNavigate, useRouter} from '@react-aria/utils';\nimport React, {RefObject} from 'react';\nimport {useFocusable} from '@react-aria/focus';\nimport {usePress} from '@react-aria/interactions';\n\nexport interface AriaLinkOptions extends AriaLinkProps {\n /** Whether the link is disabled. */\n isDisabled?: boolean,\n /**\n * The HTML element used to render the link, e.g. 'a', or 'span'.\n * @default 'a'\n */\n elementType?: string\n}\n\nexport interface LinkAria {\n /** Props for the link element. */\n linkProps: DOMAttributes,\n /** Whether the link is currently pressed. */\n isPressed: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for a link component.\n * A link allows a user to navigate to another page or resource within a web page\n * or application.\n */\nexport function useLink(props: AriaLinkOptions, ref: RefObject<FocusableElement>): LinkAria {\n let {\n elementType = 'a',\n onPress,\n onPressStart,\n onPressEnd,\n // @ts-ignore\n onClick: deprecatedOnClick,\n isDisabled,\n ...otherProps\n } = props;\n\n let linkProps: DOMAttributes = {};\n if (elementType !== 'a') {\n linkProps = {\n role: 'link',\n tabIndex: !isDisabled ? 0 : undefined\n };\n }\n let {focusableProps} = useFocusable(props, ref);\n let {pressProps, isPressed} = usePress({onPress, onPressStart, onPressEnd, isDisabled, ref});\n let domProps = filterDOMProps(otherProps, {labelable: true, isLink: elementType === 'a'});\n let interactionHandlers = mergeProps(focusableProps, pressProps);\n let router = useRouter();\n\n return {\n isPressed, // Used to indicate press state for visual\n linkProps: mergeProps(domProps, {\n ...interactionHandlers,\n ...linkProps,\n 'aria-disabled': isDisabled || undefined,\n 'aria-current': props['aria-current'],\n onClick: (e: React.MouseEvent<HTMLAnchorElement>) => {\n pressProps.onClick?.(e);\n if (deprecatedOnClick) {\n deprecatedOnClick(e);\n console.warn('onClick is deprecated, please use onPress');\n }\n\n // If a custom router is provided, prevent default and forward if this link should client navigate.\n if (\n !router.isNative &&\n e.currentTarget instanceof HTMLAnchorElement &&\n e.currentTarget.href &&\n // If props are applied to a router Link component, it may have already prevented default.\n !e.isDefaultPrevented() &&\n shouldClientNavigate(e.currentTarget, e)\n ) {\n e.preventDefault();\n router.open(e.currentTarget, e);\n }\n }\n })\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;AAmBA,gCAAiC,SAAQ,aAAa;IACpD,oCAAoC;IACpC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;IACE,kCAAkC;IAClC,SAAS,EAAE,aAAa,CAAC;IACzB,6CAA6C;IAC7C,SAAS,EAAE,OAAO,CAAA;CACnB;AAED;;;;GAIG;AACH,wBAAwB,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,UAAU,gBAAgB,CAAC,GAAG,QAAQ,CAwC1F","sources":["packages/@react-aria/link/src/packages/@react-aria/link/src/useLink.ts","packages/@react-aria/link/src/packages/@react-aria/link/src/index.ts","packages/@react-aria/link/src/index.ts"],"sourcesContent":[null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport type {AriaLinkOptions, LinkAria} from './useLink';\nexport {useLink} from './useLink';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;;AAmBA,gCAAiC,SAAQ,aAAa;IACpD,oCAAoC;IACpC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;IACE,kCAAkC;IAClC,SAAS,EAAE,aAAa,CAAC;IACzB,6CAA6C;IAC7C,SAAS,EAAE,OAAO,CAAA;CACnB;AAED;;;;GAIG;AACH,wBAAwB,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,UAAU,gBAAgB,CAAC,GAAG,QAAQ,CAsD1F","sources":["packages/@react-aria/link/src/packages/@react-aria/link/src/useLink.ts","packages/@react-aria/link/src/packages/@react-aria/link/src/index.ts","packages/@react-aria/link/src/index.ts"],"sourcesContent":[null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport type {AriaLinkOptions, LinkAria} from './useLink';\nexport {useLink} from './useLink';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/link",
3
- "version": "3.5.4",
3
+ "version": "3.6.1",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,11 +22,11 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-aria/focus": "^3.14.1",
26
- "@react-aria/interactions": "^3.18.0",
27
- "@react-aria/utils": "^3.20.0",
28
- "@react-types/link": "^3.4.5",
29
- "@react-types/shared": "^3.20.0",
25
+ "@react-aria/focus": "^3.14.3",
26
+ "@react-aria/interactions": "^3.19.1",
27
+ "@react-aria/utils": "^3.21.1",
28
+ "@react-types/link": "^3.5.1",
29
+ "@react-types/shared": "^3.21.0",
30
30
  "@swc/helpers": "^0.5.0"
31
31
  },
32
32
  "peerDependencies": {
@@ -35,5 +35,5 @@
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "54fbaa67cc56867506811819fef765546d403253"
38
+ "gitHead": "3ecf62dcceea437cb12df1851636dd491bb6591c"
39
39
  }
package/src/useLink.ts CHANGED
@@ -12,8 +12,8 @@
12
12
 
13
13
  import {AriaLinkProps} from '@react-types/link';
14
14
  import {DOMAttributes, FocusableElement} from '@react-types/shared';
15
- import {filterDOMProps, mergeProps} from '@react-aria/utils';
16
- import {RefObject} from 'react';
15
+ import {filterDOMProps, mergeProps, shouldClientNavigate, useRouter} from '@react-aria/utils';
16
+ import React, {RefObject} from 'react';
17
17
  import {useFocusable} from '@react-aria/focus';
18
18
  import {usePress} from '@react-aria/interactions';
19
19
 
@@ -60,8 +60,9 @@ export function useLink(props: AriaLinkOptions, ref: RefObject<FocusableElement>
60
60
  }
61
61
  let {focusableProps} = useFocusable(props, ref);
62
62
  let {pressProps, isPressed} = usePress({onPress, onPressStart, onPressEnd, isDisabled, ref});
63
- let domProps = filterDOMProps(otherProps, {labelable: true});
63
+ let domProps = filterDOMProps(otherProps, {labelable: true, isLink: elementType === 'a'});
64
64
  let interactionHandlers = mergeProps(focusableProps, pressProps);
65
+ let router = useRouter();
65
66
 
66
67
  return {
67
68
  isPressed, // Used to indicate press state for visual
@@ -70,12 +71,25 @@ export function useLink(props: AriaLinkOptions, ref: RefObject<FocusableElement>
70
71
  ...linkProps,
71
72
  'aria-disabled': isDisabled || undefined,
72
73
  'aria-current': props['aria-current'],
73
- onClick: (e) => {
74
+ onClick: (e: React.MouseEvent<HTMLAnchorElement>) => {
74
75
  pressProps.onClick?.(e);
75
76
  if (deprecatedOnClick) {
76
77
  deprecatedOnClick(e);
77
78
  console.warn('onClick is deprecated, please use onPress');
78
79
  }
80
+
81
+ // If a custom router is provided, prevent default and forward if this link should client navigate.
82
+ if (
83
+ !router.isNative &&
84
+ e.currentTarget instanceof HTMLAnchorElement &&
85
+ e.currentTarget.href &&
86
+ // If props are applied to a router Link component, it may have already prevented default.
87
+ !e.isDefaultPrevented() &&
88
+ shouldClientNavigate(e.currentTarget, e)
89
+ ) {
90
+ e.preventDefault();
91
+ router.open(e.currentTarget, e);
92
+ }
79
93
  }
80
94
  })
81
95
  };