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
path: root/js
diff options
context:
space:
mode:
authorJohann-S <johann.servoire@gmail.com>2017-05-17 23:03:11 +0300
committerGitHub <noreply@github.com>2017-05-17 23:03:11 +0300
commitb36d8ae6cb9dcd2e4183202a747d53706f1c1c8a (patch)
tree1da6f68097ce5d217d2eeb789d4390b7c4d4f894 /js
parentbe742b0f5cde4478402a5a11853cea35ded812ac (diff)
Use popper to align dropdown menu instead of using css with important
Diffstat (limited to 'js')
-rw-r--r--js/src/dropdown.js31
-rw-r--r--js/tests/visual/dropdown.html48
2 files changed, 65 insertions, 14 deletions
diff --git a/js/src/dropdown.js b/js/src/dropdown.js
index 39a4a86ca4..846746384b 100644
--- a/js/src/dropdown.js
+++ b/js/src/dropdown.js
@@ -52,8 +52,11 @@ const Dropdown = (($) => {
}
const ClassName = {
- DISABLED : 'disabled',
- SHOW : 'show'
+ DISABLED : 'disabled',
+ SHOW : 'show',
+ DROPUP : 'dropup',
+ MENURIGHT : 'dropdown-menu-right',
+ MENULEFT : 'dropdown-menu-left'
}
const Selector = {
@@ -142,7 +145,7 @@ const Dropdown = (($) => {
}
// Handle dropup
- const dropdownPlacement = $(this._element).parent().hasClass('dropup') ? AttachmentMap.TOP : this._config.placement
+ const dropdownPlacement = $(this._element).parent().hasClass(ClassName.DROPUP) ? AttachmentMap.TOP : this._config.placement
this._popper = new Popper(this._element, this._menu, {
placement : dropdownPlacement,
modifiers : {
@@ -151,6 +154,11 @@ const Dropdown = (($) => {
},
flip : {
enabled : this._config.flip
+ },
+ beforeApplyStyle: {
+ order: 899, // 900 is the order of applyStyle
+ enabled: true,
+ fn: this._beforePopperApplyStyle
}
}
})
@@ -230,6 +238,23 @@ const Dropdown = (($) => {
return this._menu
}
+ _beforePopperApplyStyle(data) {
+ if ($(data.instance.popper).hasClass(ClassName.MENURIGHT)) {
+ data.styles = {
+ right: 0,
+ left: 'auto'
+ }
+ }
+
+ if ($(data.instance.popper).hasClass(ClassName.MENULEFT)) {
+ data.styles = {
+ right: 'auto',
+ left: 0
+ }
+ }
+ return data
+ }
+
// static
static _jQueryInterface(config) {
diff --git a/js/tests/visual/dropdown.html b/js/tests/visual/dropdown.html
index 45c5d51722..166cbf7259 100644
--- a/js/tests/visual/dropdown.html
+++ b/js/tests/visual/dropdown.html
@@ -59,19 +59,45 @@
</li>
</ul>
- <!-- Default dropup button -->
- <div class="btn-group dropup" style="margin-top: 60px;">
- <button type="button" class="btn btn-secondary">Dropup</button>
- <button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
- <span class="sr-only">Toggle Dropdown</span>
- </button>
- <div class="dropdown-menu">
- <a class="dropdown-item" href="#">Action</a>
- <a class="dropdown-item" href="#">Another action</a>
- <a class="dropdown-item" href="#">Something else here</a>
+ <div class="row">
+ <div class="col-sm-12 mt-4">
+ <!-- Default dropup button -->
+ <div class="btn-group dropup">
+ <button type="button" class="btn btn-secondary">Dropup</button>
+ <button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+ <span class="sr-only">Toggle Dropdown</span>
+ </button>
+ <div class="dropdown-menu">
+ <a class="dropdown-item" href="#">Action</a>
+ <a class="dropdown-item" href="#">Another action</a>
+ <a class="dropdown-item" href="#">Something else here</a>
+ </div>
+ </div>
+
+ <div class="btn-group">
+ <button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+ This dropdown's menu is right-aligned
+ </button>
+ <div class="dropdown-menu dropdown-menu-right">
+ <button class="dropdown-item" type="button">Action</button>
+ <button class="dropdown-item" type="button">Another action</button>
+ <button class="dropdown-item" type="button">Something else here</button>
+ </div>
+ </div>
+
+ <div class="btn-group">
+ <button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+ This dropdown's menu is left-aligned
+ </button>
+ <div class="dropdown-menu dropdown-menu-left">
+ <button class="dropdown-item" type="button">Action</button>
+ <button class="dropdown-item" type="button">Another action</button>
+ <button class="dropdown-item" type="button">Something else here</button>
+ </div>
+ </div>
+ </div>
</div>
</div>
- </div>
<script src="../../../docs/assets/js/vendor/jquery-slim.min.js"></script>
<script src="../../../docs/assets/js/vendor/popper.min.js"></script>