Skip to content

Commit 1566ec1

Browse files
committed
Fixed issue where focus was not on first non close element
1 parent efd89f5 commit 1566ec1

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
## Release History
2+
* **0.4.5**
3+
* 🐞 `BUGFIX` Modal focus correctly focuses on non close trigger when possible
4+
* 🐞 `BUGFIX` Custom open class is now properly removed on modal close
25
* **0.4.4**
36
* 💡 `FEATURE` Added ability to customize open class name
47
* **0.4.3**

lib/src/index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ const MicroModal = (() => {
150150
setFocusToFirstNode () {
151151
if (this.config.disableFocus) return
152152

153-
const focusableNodes = this.getFocusableNodes()
153+
let focusableNodes = this.getFocusableNodes()
154154

155-
// could not think of a better name :(
156-
const nodesWhichAreNotCloseTargets = focusableNodes.filter(node => !node.hasAttribute('data-micromodal-close'))
155+
// Filters nodes which are close targets
156+
focusableNodes = focusableNodes.filter(node => !node.hasAttribute(this.config.closeTrigger))
157157

158-
if (nodesWhichAreNotCloseTargets.length > 0) nodesWhichAreNotCloseTargets[0].focus()
159-
if (nodesWhichAreNotCloseTargets.length === 0) focusableNodes[0].focus()
158+
if (focusableNodes.length > 0) focusableNodes[0].focus()
159+
if (focusableNodes.length === 0) focusableNodes[0].focus()
160160
}
161161

162162
retainFocus (event) {

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
"build": "yarn lib:build && yarn docs:build",
1818
"deploy:npm": "yarn workspace micromodal publish",
1919
"deploy:docs": "yarn workspace @micromodal/docs deploy",
20-
"lib:dev": "yarn workspace micromodal dev",
21-
"lib:build": "yarn workspace micromodal build",
2220
"docs:dev": "yarn workspace @micromodal/docs dev",
2321
"docs:build": "yarn workspace @micromodal/docs build",
22+
"lib:dev": "yarn workspace micromodal dev",
23+
"lib:build": "yarn workspace micromodal build",
2424
"test": "yarn workspace @micromodal/tests cypress:cli",
2525
"test:serve": "yarn workspace @micromodal/tests serve",
2626
"test:gui": "yarn workspace @micromodal/tests cypress:open"

0 commit comments

Comments
 (0)