{"name":"react-router-hash-link","version":"2.4.1","description":"Hash link scroll functionality for React Router v4/5","main":"dist/react-router-hash-link.cjs.js","module":"dist/react-router-hash-link.esm.js","sideEffects":false,"scripts":{"build":"rollpkg build","watch":"rollpkg watch","prepublishOnly":"npm run build","lintStaged":"lint-staged"},"repository":{"type":"git","url":"git+https://github.com/rafgraph/react-router-hash-link.git"},"keywords":["react","react-router","link","hash-link","scroll"],"author":{"name":"Rafael Pedicini","email":"rafael@rafgraph.dev"},"license":"MIT","bugs":{"url":"https://github.com/rafgraph/react-router-hash-link/issues"},"peerDependencies":{"react":">=15","react-router-dom":">=4"},"dependencies":{"prop-types":"^15.7.2"},"devDependencies":{"lint-staged":"^10.5.4","pre-commit":"^1.2.2","react":"file:demo/node_modules/react","react-router-dom":"file:demo/node_modules/react-router-dom","rollpkg":"^0.5.5","typescript":"^4.2.4"},"pre-commit":"lintStaged","lint-staged":{"(src/**/*|demo/src/**/*)":["prettier --write --ignore-unknown"]},"prettier":"rollpkg/configs/prettier.json","gitHead":"21c81d8ac6c14b4be4e1ed6fb7ca531841362ac4","homepage":"https://github.com/rafgraph/react-router-hash-link#readme","_id":"react-router-hash-link@2.4.1","_nodeVersion":"14.16.1","_npmVersion":"7.11.2","dist":{"integrity":"sha512-ac71RVRhGzr2DXHPDYW+DE7oH/jkbMefF3giSlAzF286EAHVc1t4wwr4sFNOYj9b2Flfq+FCv184Qi9MBP0KXw==","shasum":"91ccd904427f42e5ded684af0a20f45842ce0dc5","tarball":"http://registry-npm.ywwl.com/react-router-hash-link/download/react-router-hash-link-2.4.1.tgz","fileCount":10,"unpackedSize":88034,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgkKZpCRA9TVsSAnZWagAAtiIQAJrETw737PtOQ+q4u2/8\nfRQ15m0PbumOrxTnj7vV040FdMzzgMJSBTqowS8P4paK9nmafMWeuR0q+2zY\nfJs9d7eMnwEfW0zYUs+mOsio+3a0wy6LzLJ4JLhLV7gvvFxbmdDzdpFJ5TTe\n8YQPizfS0B9g9LYt0dKHvYevZ6BT0XBdokP7IX/Y3GfFljyFzkXGQFCrWE+7\nbwgWJ2Vl4M7+xBoIaF6qI2rOxcQgRCm1rfuCjJoZfn02X32N/yIyskRtjxfZ\n315kD2UQkpDZmsbdUSLA0K9Fb/4BS53otdXNvKuU9pIkn7jhcL4+U0lX+7qX\ng+6lwpWgAk83bnuggctofnCZg2gcn5M1gA7/PdpIzmiPs8Ty2Jf8K6GUh7Uv\nxUNFMD/mMzst6EZh8v1DSzpyZa8Grbc04p0wvlykyUkPY29j1zSd/rgY3p3r\n/fVMYUqP97KqifObtQFNvt0qKzl6FiLMIY9uVd2tkx5F8+Bp1MYPIh4fB/g2\nDCxs60XRjpWMqq5U9hlyBRD2uYjUrf4ZftuNzgf0RtpZ8cqqdHHN9QJMKCwC\nSbxKOOfEaQ9KRMzDfTzgu0hqoVNbjose9XQCHMjeePVAyidOXAjud+MzmAXu\nqecvwb7QOQfksZI4S4d4QpEi6SVEDBPfzOof6P3CA8vXNEfrMCrjG1jiia2L\nzBfd\r\n=jyfq\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCyoE0Zy9nPAVutfj+mRofBfzHnSwU0PY/If+oq5FcY4QIhANvB3X3m+eACRYD3ZkWQ+kn0+xTCRf7xKv6tVirzeIHt"}],"size":14990,"noattachment":false,"key":"/react-router-hash-link/-/react-router-hash-link-2.4.1.tgz"},"_npmUser":{"name":"rafgraph","email":"rafael@rafgraph.dev"},"directories":{},"maintainers":[{"name":"rafgraph","email":"rafael@rafgraph.dev"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/react-router-hash-link_2.4.1_1620092520829_0.3302098775294029"},"_hasShrinkwrap":false,"readme":"# React Router Hash Link\n\n[![npm](https://img.shields.io/npm/dm/react-router-hash-link?label=npm)](https://www.npmjs.com/package/react-router-hash-link) [![npm bundle size (version)](https://img.shields.io/bundlephobia/minzip/react-router-hash-link?color=purple)](https://bundlephobia.com/result?p=react-router-hash-link)\n\nThis is a solution to [React Router's issue of not scrolling to `#hash-fragments`](https://github.com/reactjs/react-router/issues/394#issuecomment-220221604) when using the `<Link>` component to navigate.\n\nWhen you click on a link created with `react-router-hash-link` it will scroll to the element on the page with the `id` that matches the `#hash-fragment` in the link. This will also work for elements that are created after an asynchronous data load. Note that you must use React Router's `BrowserRouter` for this to work.\n\n---\n\n### [Live demo app for React Router Hash Link](https://react-router-hash-link.rafgraph.dev)\n\nCode is in the [`/demo`](/demo) folder, or open the [demo in CodeSandbox](https://githubbox.com/rafgraph/react-router-hash-link/tree/main/demo)\n\n---\n\n## Basics\n\n```shell\nnpm install --save react-router-hash-link\n```\n\n`react-router-dom` is a peer dependency.\n\n---\n\n### `<HashLink>`\n\n```js\nimport { HashLink } from 'react-router-hash-link';\n\n...\n\n// use it just like a RRv4/5 <Link>\n// the `to` prop can be a string or an object, see RRv4/5 api for details\n<HashLink to=\"/some/path#with-hash-fragment\">Link to Hash Fragment</HashLink>\n```\n\n---\n\n### `<NavHashLink>`\n\n```js\nimport { NavHashLink } from 'react-router-hash-link';\n\n...\n\n// use it just like a RRv4/5 <NavLink> (see RRv4/5 api for details)\n// it will be active only if both the path and hash fragment match\n<NavHashLink\n  to=\"/some/path#with-hash-fragment\"\n  activeClassName=\"selected\"\n  activeStyle={{ color: 'red' }}\n  // etc...\n>Link to Hash Fragment</NavHashLink>\n```\n\n---\n\n## Scrolling API\n\n### `smooth: boolean`\n\n- Smooth scroll to the element\n- React Router Hash Link uses the native Element method `element.scrollIntoView()` for scrolling, and when the `smooth` prop is present it will call it with the smooth option, `element.scrollIntoView({ behavior: 'smooth' })`\n- Note that not all browsers have implemented options for `scrollIntoView` - see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView) and [Can I Use](https://caniuse.com/#feat=scrollintoview) - there is also a browser [polyfill for smooth scrolling](https://github.com/iamdustan/smoothscroll) which you can install separately so `smooth` will work in all browsers\n\n```js\nimport { HashLink } from 'react-router-hash-link';\n\n...\n\n<HashLink smooth to=\"/path#hash\">\n  Link to Hash Fragment\n</HashLink>;\n```\n\n---\n\n### `scroll: function`\n\n- Custom scroll function called with the element to scroll to, e.g. `const myScrollFn = element => {...}`\n- This allows you to do things like scroll with offset, use a specific smooth scrolling library, or pass in your own options to `scrollIntoView`\n\n```js\nimport { HashLink } from 'react-router-hash-link';\n\n...\n\n<HashLink\n  to=\"/path#hash\"\n  scroll={(el) => el.scrollIntoView({ behavior: 'auto', block: 'end' })}\n>\n  Link to Hash Fragment\n</HashLink>;\n```\n\n---\n\n### Scroll to top of page\n\n- To scroll to the top of the page set the hash fragment to `#` (empty) or `#top`\n- This is inline with the [HTML spec](https://html.spec.whatwg.org/multipage/browsing-the-web.html#target-element), also see [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#Linking_to_an_element_on_the_same_page)\n\n```js\nimport { HashLink } from 'react-router-hash-link';\n\n...\n\n<HashLink to=\"/path#top\">Link to Top of Page</HashLink>\n// or\n<HashLink to=\"#top\">Link to Top of Page</HashLink>\n```\n\n---\n\n### Scroll with offset\n\n- To scroll with offset use a custom scroll function, one way of doing this can be found [here](https://github.com/rafgraph/react-router-hash-link/issues/25#issuecomment-536688104)\n\n---\n\n### `elementId: string`\n\n- Scroll to the element with matching id\n- Used instead of providing a hash fragment as part of the `to` prop, if both are present then the `elementId` will override the `to` prop's hash fragment\n- Note that it is generally recommended to use the `to` prop's hash fragment instead of the `elementId`\n\n---\n\n## Custom `Link`\n\nThe exported components are wrapped versions of the `Link` and `NavLink` exports of react-router-dom. In some cases you may need to provide a custom `Link` implementation.\n\nFor example, the gatsby static site generator requires you to use its implementation of `Link`. You can wrap it with the `genericHashLink` function of this package.\n\n```jsx\nimport { genericHashLink } from 'react-router-hash-link';\nimport GatsbyLink from 'gatsby-link';\n\nconst MyHashLink = genericHashLink(GatsbyLink);\n\nconst MyComponent = () => (\n  <div>\n    The default wont work for you?\n    <MyHashLink to=\"/faq#how-to-use-custom-link\">No problem!</MyHashLink>\n  </div>\n);\n```\n\n---\n\n## Focus Management\n\n`react-router-hash-link` attempts to recreate the native browser focusing behavior as closely as possible.\n\nThe browser native behavior when clicking a hash link is:\n\n- If the target element is not focusable, then focus is _moved_ to the target element, but the target element is not focused.\n- If the target element is focusable (interactive elements and elements with a `tabindex`), then the target element is focused.\n\nTo recreate this `react-router-hash-link` does the following:\n\n- For non-focusable elements, it calls `element.focus()` followed by `element.blur()` (using a temporary `tabindex` to ensure that the element can be focused programmatically) so that focus _moves_ to the target element but does not remain on it or trigger any style changes.\n- For focusable elements, it calls `element.focus()` and leaves focus on the target element.\n\nNote that you may find it useful to leave focus on non-interactive elements (by adding a `tabindex` of `-1`) to augment the navigation action with a visual focus indicator.\n","publish_time":1620092521024,"_cnpm_publish_time":1620092521024,"dist-tags":{"latest":"2.4.3","next":"2.4.0-next.0"}}