3.9.3 • Published 6 days ago

react-focus-on v3.9.3

Weekly downloads
62,773
License
MIT
Repository
github
Last release
6 days ago

The final solution for WAI ARIA compatible Modal Dialogs or any full-screen tasks:

Now you could focus on a single task.

This is basically the inert

Minimal size - no more than 2kb, maximal - no more that 6kb. See sidecar example for details.

Example

Code sandbox example - https://codesandbox.io/s/p3vjp8mzw7

import {FocusOn} from 'react-focus-on';

<FocusOn
 onClickOutside={callback}
 onEscapeKey={callback}
 shards={[externalRef]}
>
 content you should be "focused" on
</FocusOn>

API

FocusOn

FocusOn - the focus on component

  • enabled - controls behaviour
  • [shards] - a list of Refs to be considered as a part of the Lock. A way to properly handle portals or scattered lock.


  • [gapMode] - the way removed ScrollBar would be compensated - margin(default), or padding. See scroll-locky documentation to find the one you need.
  • [noIsolation] - disables aria-hidden isolation
  • [inert] - enables pointer-events isolation (☠️ dangerous, use to disable "parent scrollbars", refer to react-remove-scroll documentation)
  • [allowPinchZoom] - enables "pinch-n-zoom" behavior. By default it might be prevented, refer to react-remove-scroll documentation
  • [preventScrollOnFocus] - prevents a side effect of a programatic page scroll caused by focusing elements. Especially useful to address modal animations.

  • [onActivation] - on activation callback
  • [onDeactivation] - on deactivation callback

  • [onClickOutside] - on click outside of "focus" area. (actually on any event "outside")
  • [onEscapeKey] - on Esc key down (and not defaultPrevented)

Additional API

Exposed from React-Focus-Lock

  • AutoFocusInside - to mark autofocusable element
  • MoveFocusInside - to move focus inside a component on mount
  • InFocusGuard - to "guard" a shard node (place an invisible node before and after)

See react-focus-lock documentation for details.

Exposed from React-Remove-Scroll

  • classNames.fullWidth - "100%" width (will not change on scrollbar removal)
  • classNames.zeroRight - "0" right (will not change on scrollbar removal)

See react-remove-scroll for details.

PS: Version 1 used React-scroll-locky which was replaced by remove-scroll.

Size

  • (🧩 full) 5.7kb after compression (excluding tslib).

  • (👁 UI) 2kb, visual elements only
  • (🚗 sidecar) 4kb, side effects

Import full

import {FocusOn} from 'react-focus-on';

<FocusOn>
 {content}
</FocusOn> 

Import UI only

import {FocusOn} from 'react-focus-on/UI';
import {sidecar} from "use-sidecar";

const FocusOnSidecar = sidecar(  
  () => import(/* webpackPrefetch: true */ "react-focus-on/sidecar")
);

<FocusOn
    sideCar={FocusOnSidecar}
>
 {content}
</FocusOn> 

React versions

  • v1 and v2 might work with React 15/16
  • v3 require React 16.8+ (hooks)

Licence

MIT

@yattho/gatsby-theme-rigitus@codecademy/gamut-labs@codecademy/gamutcl2-front@joey.andres/eui@infinitebrahmanuniverse/nolb-react-fo@everything-registry/sub-chunk-2555@vectara/search@ethomson/gatsby-theme-npm-doctocat@inoft/eui@ifrc-go/ui@edhos/ui@elastic/eui@edx/paragon@edunext/paragong-nimbus-ui@kothawleprem/vectara-react-chatbot@kothawleprem/vectara-react-search-metadatafilter@lanyun_cd/elastic_ui@lanyun_cd/euigatsby-theme-doctornpm@littlespoon/drawer@pjfitzgibbons/oui@primer/doctocat-nextjs@primer/gatsby-theme-doctocat@sami616/componentsfury-design-system@kaizen/draft-title-block-zen@kaizen/components@kaizen/date-pickerwazuh-wui@randomnerd/euijitsi-meet-stepup@open-codes/opencodes@palustris/react-images@opensearch-project/oui@opensearch-staging/ouigatsby-theme-primer-wikigatsby-theme-wikinotes@moda/om@muusa/eui@oclock/crumble@openedx/paragon@zalastax/nolb-react-fo@wazuh/wui@vectara/react-chatbot@vectara/react-search@wonderflow/react-components@westpac/modal@westpac/sidebar@wedgekit/modal@wedgekit/popover@start-base/react-form-elements@superficial-ui/components@superficial-ui/coremdlz-prmtz@tensei/euimolekule@umuthopeyildirim/react-chatbot@ulugbekov/react-images@actionishope/shelley@actionishope/shelley-puma@actovos-consulting-group/ui-core@adventera/vectara-ui@bc-digital/bronte@bannv/eui-latest@bsfishy/oui@commonground/design-system@bridgetool/gatsby-theme-dev@amorphic/amorphic-ui-core@artsy/palette@auspices/eosoneai-analytics@department-of-veterans-affairs/react-components@department-of-veterans-affairs/component-library@dej611/spid-react-buttoncreedcustomizedelasticuiforc1react-images-lazy-loadreact-imagesspid-react-button-update@david-vectara/react-chatbotreact-images2terra-abstract-modal
3.9.3

6 days ago

3.9.2

2 months ago

3.9.1

10 months ago

3.8.2

10 months ago

3.9.0

10 months ago

3.8.1

12 months ago

3.8.0

1 year ago

3.7.0

1 year ago

3.6.0

2 years ago

3.5.4

2 years ago

3.5.3

2 years ago

3.5.2

3 years ago

3.5.1

3 years ago

3.5.0

4 years ago

3.4.1

4 years ago

3.4.0

4 years ago

3.3.0

5 years ago

3.2.0

5 years ago

3.1.5

5 years ago

3.1.4

5 years ago

3.1.3

5 years ago

3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.7

5 years ago

3.0.6

5 years ago

3.0.5

5 years ago

3.0.4

5 years ago

3.0.3

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.0.0-beta.1

6 years ago

0.0.0-beta

6 years ago