Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRohit Sharma <rohit2sharma95@gmail.com>2021-04-20 08:19:57 +0300
committerGitHub <noreply@github.com>2021-04-20 08:19:57 +0300
commitb59b75bc55ad9d5d2d0259f6b3364a7bcb82b033 (patch)
tree95009186c927d217575e7e4a6ae9f4afa0fd3c67 /js/src/dropdown.js
parenta22f4d3cfd46ad040e0eb636c378fdb832704e07 (diff)
Dropdown — Add option to make the dropdown menu clickable (#33389)
Diffstat (limited to 'js/src/dropdown.js')
-rw-r--r--js/src/dropdown.js20
1 files changed, 13 insertions, 7 deletions
diff --git a/js/src/dropdown.js b/js/src/dropdown.js
index 2fc2cde21b..d26fa96cab 100644
--- a/js/src/dropdown.js
+++ b/js/src/dropdown.js
@@ -75,7 +75,8 @@ const Default = {
boundary: 'clippingParents',
reference: 'toggle',
display: 'dynamic',
- popperConfig: null
+ popperConfig: null,
+ autoClose: true
}
const DefaultType = {
@@ -83,7 +84,8 @@ const DefaultType = {
boundary: '(string|element)',
reference: '(string|element|object)',
display: 'string',
- popperConfig: '(null|object|function)'
+ popperConfig: '(null|object|function)',
+ autoClose: '(boolean|string)'
}
/**
@@ -127,9 +129,8 @@ class Dropdown extends BaseComponent {
const isActive = this._element.classList.contains(CLASS_NAME_SHOW)
- Dropdown.clearMenus()
-
if (isActive) {
+ this.hide()
return
}
@@ -424,7 +425,7 @@ class Dropdown extends BaseComponent {
for (let i = 0, len = toggles.length; i < len; i++) {
const context = Data.get(toggles[i], DATA_KEY)
- if (!context) {
+ if (!context || context._config.autoClose === false) {
continue
}
@@ -437,8 +438,13 @@ class Dropdown extends BaseComponent {
}
if (event) {
- // Don't close the menu if the clicked element or one of its parents is the dropdown button
- if ([context._element].some(element => event.composedPath().includes(element))) {
+ const composedPath = event.composedPath()
+ const isMenuTarget = composedPath.includes(context._menu)
+ if (
+ composedPath.includes(context._element) ||
+ (context._config.autoClose === 'inside' && !isMenuTarget) ||
+ (context._config.autoClose === 'outside' && isMenuTarget)
+ ) {
continue
}