{"id":15639916,"url":"https://github.com/jossmac/react-focus-marshal","last_synced_at":"2025-04-15T11:07:51.874Z","repository":{"id":66030326,"uuid":"136456046","full_name":"jossmac/react-focus-marshal","owner":"jossmac","description":"👮🏻 Traps focus within a DOM node","archived":false,"fork":false,"pushed_at":"2018-10-12T01:31:26.000Z","size":150,"stargazers_count":82,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T11:07:37.548Z","etag":null,"topics":["focus","focuslock","react","trap"],"latest_commit_sha":null,"homepage":"https://jossmac.github.io/react-focus-marshal","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jossmac.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-07T09:43:57.000Z","updated_at":"2024-06-21T00:17:24.000Z","dependencies_parsed_at":"2023-03-10T23:30:40.200Z","dependency_job_id":null,"html_url":"https://github.com/jossmac/react-focus-marshal","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jossmac%2Freact-focus-marshal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jossmac%2Freact-focus-marshal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jossmac%2Freact-focus-marshal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jossmac%2Freact-focus-marshal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jossmac","download_url":"https://codeload.github.com/jossmac/react-focus-marshal/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249058370,"owners_count":21205910,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["focus","focuslock","react","trap"],"created_at":"2024-10-03T11:28:13.329Z","updated_at":"2025-04-15T11:07:51.846Z","avatar_url":"https://github.com/jossmac.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Focus Marshal\n\nTraps focus within a DOM node — subsequently mounted traps will take control of focus and pause others until unmounted.\n\n### Install\n\n```bash\nyarn add react-focus-manager\n```\n\n### Use\n\nYou must wrap the applicable section of your app in the `FocusMarshal`, which provides context to the `FocusTrap` descendants.\n\n```jsx\nimport { FocusTrap, FocusMarshal } from 'react-focus-marshal';\n\nconst Modal = () =\u003e createPortal(\n  \u003cFocusTrap\u003e\n    \u003cdiv\u003e\n      {/* modal content */}\n    \u003c/div\u003e\n  \u003c/FocusTrap\u003e,\n  document.body\n);\n\nconst App = () =\u003e (\n  \u003cFocusMarshal\u003e\n    {someCondition ? \u003cModal /\u003e : null}\n  \u003c/FocusMarshal\u003e\n);\n```\n\n## FocusMarshal Props\n\n| Property | Description |\n| ------------- | ------------- |\n| children `Node` | All children are passed through. |\n\n## FocusTrap Props\n\n| Property | Description |\n| ------------- | ------------- |\n| children \u003ccode\u003eElement\u0026lt;HTMLElement \u0026#124; ComponentType\u0026gt;\u003c/code\u003e | A single element to trap focus within. The underlying DOM node will be resolved on the component passed as children. |\n| Options `OptionsType` | The options object that is passed to `createFocusTrap`. See below for definition. |\n\n#### Acknowledgement\nThe `FocusTrap` component is a thin wrapper around David Clark's fantastic [focus-trap](https://github.com/davidtheclark/focus-trap) library. Whilst react-focus-marshal attempts to maintain feature parity, there are some minor differences; see `fallbackFocus` property below.\n\n### OptionsType\n\nFor brevity:\n- `FocusTarget` is equal to `HTMLElement | string | () =\u003e HTMLElement`.\n- `ActivationFn` is equal to `Ref =\u003e void`.\n\n| Property | Description   |\n| ------------- | -------------   |\n| onActivate `ActivationFn` | A function that will be called when the focus trap activates.   |\n| onDeactivate `ActivationFn` | A function that will be called when the focus trap deactivates. |\n| initialFocus `FocusTarget` | Defaults to the first \"tabbable\" element -- a string value will be passed to `document.querySelector()`.|\n| ~~fallbackFocus~~ `FocusTarget` | The required `children` element is used as a safe way to fulfill the contract with \"focus-trap\". |\n| escapeDeactivates `boolean` | Default: `true`. If false, the Escape key will not trigger deactivation of the focus trap. |\n| clickOutsideDeactivates `boolean` | Default: `false`. If true, a click outside the focus trap will deactivate the focus trap and allow the click event to do its thing. |\n| returnFocusOnDeactivate `boolean` | Default: `true`. If false, when the trap is deactivated, focus will not return to the element that had focus before activation. |\n\n## Alternatives\n\nThis library may not meet your needs. Here are some alternative I came across whilst searching for this solution:\n\n- https://github.com/davidtheclark/focus-trap\n- https://github.com/davidtheclark/focus-trap-react\n- https://github.com/theKashey/react-focus-lock\n- https://github.com/vigetlabs/react-focus-trap\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjossmac%2Freact-focus-marshal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjossmac%2Freact-focus-marshal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjossmac%2Freact-focus-marshal/lists"}