Skip to content

Releases: discord/focus-layers

v0.6.1 - More autoFocus fixing and no more rAF

07 Mar 06:19
Compare
Choose a tag to compare

This version (hopefully) actually fixes the autoFocus problem by breaking out of React's useEffect callback ordering and updating layer enabled/disabled states immediately (#16).

v0.6.0 - Returns, autofocus, and CJS support

04 Mar 19:33
Compare
Choose a tag to compare
  • Re-added the ability to specify a different target for returning focus when a layer is popped (#7, #13)
  • Fixed issues with autoFocus appearing broken when a lock layer is added on top of another (#12, #14)
  • Added useFocusLock as a named export for better compatibility in CJS modules (#11, #15)

v0.5.1 - Allow disabling focus returns

29 May 18:30
Compare
Choose a tag to compare

v0.5.0 - Documentation and edge cases

27 May 07:45
Compare
Choose a tag to compare

All components of the package are now documented with descriptive context. The code has been split up into multiple distinct modules to improve readability with those comments inline. Finally, a number of edge cases have been addressed to improve stability and fix incorrect behavior with various blur and refocus situations.

v0.4.1

16 May 22:14
Compare
Choose a tag to compare
v0.4.1

v0.4.0 - Tracking enabled states in the stack

16 May 21:50
Compare
Choose a tag to compare

Mainly an improvement for debugging, the lock stack now tracks whether a layer thinks it's enabled or not directly. This is simple extension of how setEnabled is called for each layer during usage.

Also, focus events that cause a wrap will now call preventDefault.

v0.3.0 - Scoped roots with `attachTo` option

30 Apr 02:49
Compare
Choose a tag to compare

The call signature for useFocusLock now uses an object as the second parameter to contain multiple optional arguments.

This also adds the attachTo option to scope where useFocusLock will attach listeners. Any focus events that occur outside of that node will not be intercepted. This is useful for apps that are embedded in other pages, or where some utilities need to focus elements outside of the lock layer to do their job (e.g., copying data with execCommand).

As a result of this change, withFocusLayer has also been removed as it was not a safe guarantee that locks would be disabled by the time the callback was invoked.

v0.2.1 - Imperative layers with `withFocusLayer`

29 Apr 06:45
Compare
Choose a tag to compare

withFocusLayer is an imperative utility for performing an action with a free focus layer added to the top of the lock stack. Useful for callback functions that need to move focus around the DOM, such as copy functions that use the browser's Selection API:

import useFocusLock, {withFocusLayer} from 'focus-layers';

function handleCopy(someText: string) {
  withFocusLayer(() => {
    // Programmatically focus anywhere you want while
    // inside this callback.
    doTheCopy(someText);
  });
}

function Dialog() {
  // This component pushes a focus layer while it is mounted.
  const containerRef = React.useRef<HTMLDivElement>(null);
  useFocusLock(containerRef);

  return (
    <div ref={containerRef}>
      <button onClick={() => copy("the copied text")}>Copy some text</button>
    </div>
  );
}

v0.2.0 - `useLockSubscription` and examples script

28 Apr 08:20
Compare
Choose a tag to compare

useLockSubscription is an easy way to subscribe to the lock stack inside of a component lifecycle.

Run yarn examples (or npm run examples) to load a demo app from the examples/ directory of this repo in your browser.