- d4a4c34: Replace findIndex with native implementation - [Closes #1305](#1305
- fc5910d: Fix fallbackFocus not used when initialFocus is selector to non-existent node (#1218)
- 8aeacee: Move
Escape
key handler to target phase to allow more control inescapeDeactivates
(#1247)
- 680f6e8: Fix issue with not being able to cycle back to the start from the last element if there is a focusable web component inside the focus-trap ((#1068)[#1068])
- 203b322: Fix missing typings for initialFocus option (#1060)
- b73eb02: Remove references to
Array.prototype.findLast()
not well supported in Safari (#996)
- d9e2546: Fix possible exception in new
Tabbable.getTabIndex()
when initializing trap
- 5e2f913: Adds support for nodes with a positive tabindex in single-container traps only (#375)
- 134678b: Ensure focus is kept inside the trap when focused element is removed from the DOM (focus-trap/focus-trap-react#962)
- db62ce3: Clicking on open shadowDOM components within a focus trap's container when
clickOutsideDeactivates=true
should not deactivate the focus trap. (#959)
- 4f720ff: Bump tabbable to v6.1.2 for nwsapi patch
- da97007: Added new onPost/Pause and onPost/Unpause hooks when un/pausing a trap (also called when auto-un/paused as a result of de/activating a second trap while another is currently active). (focus-trap-react#948)
- a00cfa5: Bump tabbable to v6.1.1 for JSDom fixes
- ae7129d: Bump tabbable to v6.1.0 adding support for the new HTML
inert
attribute in browsers that support it (NOTE: FireFox does not support it at this time). Also fixes a bug. See tabbable CHANGELOG for more info.
- a27ad58: Fix incorrect behavior of
returnFocusOnDeactivate
option when set to true (or defaulted to true) along withclickOutsideDeactivates=true
and the outside click that deactivates is on a focusable node. Focus was remaining on that node instead of returning to the node focused just prior to activation. (#893)
- b0482af: Add new
isKeyForward()
andisKeyBackward()
options (#612)
- 88cc9bc: Provide new
trapStack
option to make it possible to coordinate auto-activation/pausing between multiplefocus-trap
instances on the same page.
- 4f97b38: Bump tabbable to v6.0.1 for a bug fix. See tabbable's changelog for more details.
- f13de76: Mention special Safari setting to enable normal DOM-based tab order in README. #783
- 5b64423: Revised and clarified official browser support (still as broad and deep as reasonably possible).
- 47f62ac: 🚨 Breaking: Tabbable dependency has been updated to v6.0.0 and contains a breaking change related to detached nodes with its default
displayCheck
setting. See tabbable's changelog for more information. - 5b64423: 🚨 Breaking: Dropped support of IE browsers, all versions.
- IE11 was officially retired on June 15, 2022 (6 weeks ago). There are no longer any versions of IE that are still maintained or even supported by Microsoft.
- f68882e: Fix docs and typings to clarify that initialFocus, fallbackFocus, and setReturnFocus options can be functions that also return selector strings.
- 8a8b1f1: Bump tabbable to v5.3.3 to pick up a small bug fix to web component (shadow DOM) support.
- ef0ce48: Handle unexpected param (true) passed as the value for the
initialFocus
,fallbackFocus
, andsetReturnFocus
options: Ignore and perform default behavior.
- 83262a7: Bumps tabbable to v5.3.2 to pick-up a fix to
displayCheck=full
(default) option behavior that caused issues with detached nodes.
- 2a57e4b: Add new
trap.active
andtrap.paused
readonly state properties on the trap so that the trap's active/paused state can be queried.
- 8fd49df: Fixed bug where
clickOutsideDeactivate
handler would get called on the 'click' event even if the node clicked was in the trap. As with 'mousedown' and 'touchstart' events where this option is also used, the handler should only get called if the target node is outside the trap. - c32c60a: Fixed: onDeactivate, onPostDeactivate, and checkCanReturnFocus options originally given to createFocusTrap() were not being used by default when calling
trap.deactivate({...})
with an option set even if that option set didn't specify any overrides of these options.
- 7c86111:
- Bump tabbable to
^5.3.1
(fixing previous update which was incorrectly set to5.3.0
). - Fix
tabbableOptions
not being used in all internal uses of tabbable APIs. - Expose
displayCheck
option intabbableOptions
typings and pass it through to tabbable APIs. - Add info to README about testing traps in JSDom (which is not officially supported).
- Bump tabbable to
- 21458c9: Bumps tabbable to v5.3.0 and includes all changes from the past v6.8.0 beta releases. The big new feature is opt-in Shadow DOM support in tabbable, and a new
getShadowRoot
tabbable option exposed in a newtabbableOptions
focus-trap config option.⚠️ This will likely break your tests if you're using JSDom (e.g. with Jest). See testing in JSDom for more info.
- When updating tabbable nodes, make sure that
getShadowRoot
tabbable option is also passed tofocusable()
. - Fix bug where having a tabbable node inside a web component in the middle of a tab sequence would cause the tab key to seemingly stop working just before focus should move to it ((#643)[#643]).
- Bumps tabbable to
v5.3.0-beta.1
- Previous beta didn't include new source. This one does.
- Adds new
tabbableOptions
configuration option, which allows specifically for the newgetShadowRoot
Tabbable configuration option:focusTrap.createFocusTrap(rootElement, { tabbableOptions: { getShadowRoot: (node) => closedShadowRoot } })
, for example (where your code has the reference toclosedShadowRoot
previously created onnode
which Tabbable cannot find on its own). - Bumps tabbable to
v5.3.0-beta.0
- ab20d3d: Fix issue with focusing negative tabindex node and then tabbing away when this node is not the last node in the trap's container ((#611)[#611])
- c932330: Fixed bug where tabbing forward from an element with negative tabindex that is last in the trap would result in focus remaining on that element (565)
- 28a069f: Fix bug from #504 where it's no longer possible to create a trap without any options [#525]
- 893dd2c: Add
document
option to support focus traps inside<iframe>
elements (#97) - 244f0c1: Extend the
setReturnFocus
option to receive a reference to the element that had focus prior to the trap being activated when a function is specified. Additionally, the function can now returnfalse
to leave focus where it is at the time of deactivation. (#485)
- 60162eb: Fix bug where
KeyboardEvent
was not being passed toescapeDeactivates
option when it's a function (#498) - 7b6abfa: Fix how focus-trap determines the event's target, which was preventing traps inside open shadow DOMs from working properly (#496)
- 14b0ee8: Fix
initialFocus
option not supporting function returningfalse
as documented (#490)
- 24063d7: Update tabbable to v5.2.1 to get bug fix for disabled fieldsets.
-
281e66c: Add option to allow no initial focus when trap activates via
initialFocus: false
There may be cases where we don't want to focus the first tabbable element when a focus trap activates.
Examples use-cases:
- Modals/dialogs
- On mobile devices where "tabbing" doesn't make sense without a connected Bluetooth keyboard
In addition, this change ensures that any element inside the trap manually focused outside of
focus-trap
code will be brought back in focus if focus is somehow found outside of the trap.Example usage:
When the trap activates, there will be no initially focused element inside the new trap.
const focusTrap = createFocusTrap('#some-container', { initialFocus: false, });
-
75be463:
escapeDeactivates
can now be either a boolean (as before) or a function that takes an event and returns a boolean.
- e2294f0: Fix race condition when activating a second trap where initial focus in the second trap may be thwarted because pausing of first trap clears the
delayInitialFocus
timer created for the second trap before during its activation sequence.
- c38bf3f: onPostDeactivate should always be called even if returnFocus/OnDeactivate is disabled.
- 278e77e: Adding 4 new configuration event options to improve support for animated dialogs and animated focus trap triggers:
checkCanFocusTrap()
,onPostActivate()
,checkCanReturnFocus()
, andonPostDeactivate()
.
- 8d11e15: Improve docs and types for most options, adding
SVGElement
as a supported type of "DOM node" since it supports thefocus()
method, same asHTMLElement
.
- 21c82ce: Bump tabbable from 5.1.6 to 5.2.0. There should be no changes in behavior as a result of this upgrade as
focus-trap
does not currently leverage the newdisplayCheck
option.
- 1baf62e: Fix focus trapped on initial focus container with tabindex=-1 when pressing shift+tab (#363)
- a882d62:
clickOutsideDeactivates
can now also be a function that returns aboolean
, similar toallowOutsideClick
. The function receives theMouseEvent
that triggered the click. (#289)
- 4d67dee: Fix a focus escape when pressing TAB after hiding element with focus (#281)
- ca32014: Bump tabbable from 5.1.4 to 5.1.5
- 036a72e: Fix crash in IE due to use of
Array.findIndex()
not supported in that browser (#257)
- fd3f2d1: Fix a bug where a multi-container trap would cease to work if all tabbable nodes were removed from one of the containers (fixes #223). As a result, an error is now thrown if the trap is left in a state where none of its containers contain any tabbable nodes (unless a
fallbackFocus
node has been configured in the trap's options). Also, the most-recently-focused node is more reliably tracked now, should focus somehow escape the trap and be brought back in by the trap, resulting in the truly most-recently-focused node to regain focus if that ever happens.
- f0c2aff: Bump tabbable to 5.1.4 for bug fix.
- 2ba512b:
- Refactored code to use function declarations instead of hoisted functions (this should have no bearing on functionality in the build output included in
./dist
. - Fixed bugs where
trap.activate()
andtrap.deactivate()
would not always return the trap (now they do in all circumstances).
- Refactored code to use function declarations instead of hoisted functions (this should have no bearing on functionality in the build output included in
- d26d2e1: Refactoring to use const/let, and simplify a few lines. This does NOT impact the build output published in
./dist
, however, and hence does not impact browser support.
- 2267d17: Adding support for multiple elements to be passed in #217
- 38b6b98: Update tabbable to 5.1.3 to get bug fixes related to detail and summary elements.
- 6a39217: Close the gap with #172 and bump
tabbable
to 5.1.2 which has a similar fix. - 756c79d: Fix #172 (again): Transpile ESM bundle down to the same browser target used for the CJS and UMD bundles. ESM is just the module system, not the browser target.
- 00674dd: Fix #172: Transpile non-minified bundles so they are compatible with IE11.
- 679009b: Update tabbable dependency to 5.1.1 to get transpiled non-minified bundles.
- fe2b0ad: Fixed #103:
returnFocusOnDeactivate
is now respected on auto-deactivation withclickOutsideDeactivates=true
.
- 5174ce1: Add delayInitialFocus option
- 53b906b: Change
prepublishOnly
script toprepare
script so that it also runs if someone installs the package directly from the git repo (e.g. from your work in which you fixed a bug or added a feature you're waiting to get merged to master and published to NPM). - 31bb28e: Update tabbable dependency to 5.1.0. The most significant update for focus-trap is a bug fix related to fixed-position containers.
- 694e2fa: Package main/module entries no longer point to minified bundles.
- Add boolean value support for
allowOutsideClick
option. - New
preventScroll
feature to prevent scrolling to the element getting focus if not in the viewport. - Changed code formatting to use dangling commas where ES5 supports them.
- BREAKING: Updated tabbable dependency to the new 5.0.0 release which contains breaking changes to its
isTabbableRadio()
internal function. - Help with tree shaking by having
package.json
statesideEffects: false
to mark this module as having no side effects as a result of merely importing it. - BREAKING: This
package.json
's "main" no longer points to./index.js
in the package (although it still points to a CJS module, so it's possible this actually doesn't break anything). It now has:- "main":
dist/focus-trap.min.js
(the CJS bundle) - "module":
dist/focus-trap.esm.min.js
(the new ESM bundle) - the UMD is
dist/focus-trap.umd.min.js
if needed (convenient for loading directly in an older browser that doesn't support ESM) - NOTE: The CJS build no longer provides a function as a default export. Use
const { createFocusTrap } = require('focus-trap');
to get the function from before. - NOTE: The ESM build does not provide a default export. Use
import { createFocusTrap } from 'focus-trap';
to import the module.
- "main":
- New ESM Build: Included in
dist/focus-trap.esm.*
. - New UMD Build: Included in
dist/focus-trap.umd.*
.
- Add
setReturnFocus
option that allows you to set which element receives focus when the trap closes.
- Add
allowOutsideClick
option that allows you to pass a click event through, even whenclickOutsideDeactivates
isfalse
.
- Update Tabbable to improve performance (see Tabbable's changelog).
- Breaking (kind of): if the
onActivate
callback changes the list of tabbable nodes and theinitialFocus
option is not used, the initial focus will still go to the first element present before the callback. - Improve performance of activating a trap.
- Register document-level event listeners as active (
passive: false
).
- Fix reference to root element that caused errors within Shadow DOM.
(Release 4.0.1 was a mistake, containing no changes.)
- Breaking (kind of): Focus trap now manages a queue of traps, so when a trap is paused because another trap activates, it will be unpaused when that other trap deactivates. If Trap A was automatically paused because Trap B activated (existing behavior), when Trap B is deactivated Trap A will be automatically unpaused (new behavior).
- Breaking (kind of): Update Tabbable to detect more elements and be more careful with radio buttons (see Tabbable's changelog).
- Breaking (kind of): If
clickOutsideDeactivates
andreturnFocusOnDeactivate
are bothtrue
, focus will be returned to the pre-trap element only if the clicked element is not focusable.
- Add slight delay before moving focus to the first element in the trap. This should prevent an occasional bug caused when the first element in the trap will close the trap if it picks up on the event that triggered the trap's opening.
- Fix
"main"
field inpackage.json
.
- Publish UMD build so people can download it from
unpkg.com
.
- Fixed: TypeScript signature for
activate
function.
- Added: TypeScript declaration file.
- Fixed: Activation does not re-focus already-focused node.
- Fixed: Tabbing works as expected when initially focused Node has a negative
tabindex
and is in the middle of other tabbable elements.
- Added:
initialFocus
andfallbackFocus
options can take functions that return DOM nodes. - Fixed:
pause
andunpause
cannot accidentally add extra event listeners.
- Added/fixed, depending on your perspective: If focus is already inside the focus trap when it is activated, leave focus where it is instead of forcing it to the first tabbable node or
initialFocus
.
- Added:
fallbackFocus
option.
- Fixed:
clickOutsideDeactivates
no longer triggers deactivation when you click inside the trap.
- Fix bug when activating multiple focus traps.
- Rewrote the thing, altering the API. Read the new docs please.
- Update
tabbable
to fix handling of traps with changing contents.
- Improve
clickOutsideDeactivates
functionality.
- Add
clickOutsideDeactivates
option. - Add
escapeDeactivates
option.
- Make sure to
select()
<input>
elements when they receive focus via tab.
- Fix buggy attempts to focus nodes that don't exist.
- Initial release.