Releases: discord/focus-layers
v0.6.1 - More autoFocus fixing and no more rAF
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
v0.5.1 - Allow disabling focus returns
bump 0.5.1
v0.5.0 - Documentation and edge cases
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
v0.4.1
v0.4.0 - Tracking enabled states in the stack
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
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`
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
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.