Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Bootstrap
bootstrap
Commits
b36d8ae6
Commit
b36d8ae6
authored
7 years ago
by
Johann-S
Committed by
GitHub
7 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Use popper to align dropdown menu instead of using css with important
parent
be742b0f
6 merge requests
!28721
Hot test
,
!27561
Adds font-weight-medium to font weight classes
,
!25326
Adjust examples
,
!23995
Add back cursor: pointer for .btn-link
,
!23178
Spinner
,
!17021
v4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
js/src/dropdown.js
+28
-3
js/src/dropdown.js
js/tests/visual/dropdown.html
+37
-11
js/tests/visual/dropdown.html
scss/_dropdown.scss
+0
-14
scss/_dropdown.scss
with
65 additions
and
28 deletions
+65
-28
js/src/dropdown.js
+
28
-
3
View file @
b36d8ae6
...
@@ -52,8 +52,11 @@ const Dropdown = (($) => {
...
@@ -52,8 +52,11 @@ const Dropdown = (($) => {
}
}
const
ClassName
=
{
const
ClassName
=
{
DISABLED
:
'
disabled
'
,
DISABLED
:
'
disabled
'
,
SHOW
:
'
show
'
SHOW
:
'
show
'
,
DROPUP
:
'
dropup
'
,
MENURIGHT
:
'
dropdown-menu-right
'
,
MENULEFT
:
'
dropdown-menu-left
'
}
}
const
Selector
=
{
const
Selector
=
{
...
@@ -142,7 +145,7 @@ const Dropdown = (($) => {
...
@@ -142,7 +145,7 @@ const Dropdown = (($) => {
}
}
// Handle dropup
// 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
,
{
this
.
_popper
=
new
Popper
(
this
.
_element
,
this
.
_menu
,
{
placement
:
dropdownPlacement
,
placement
:
dropdownPlacement
,
modifiers
:
{
modifiers
:
{
...
@@ -151,6 +154,11 @@ const Dropdown = (($) => {
...
@@ -151,6 +154,11 @@ const Dropdown = (($) => {
},
},
flip
:
{
flip
:
{
enabled
:
this
.
_config
.
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 = (($) => {
...
@@ -230,6 +238,23 @@ const Dropdown = (($) => {
return
this
.
_menu
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
static
_jQueryInterface
(
config
)
{
static
_jQueryInterface
(
config
)
{
...
...
This diff is collapsed.
Click to expand it.
js/tests/visual/dropdown.html
+
37
-
11
View file @
b36d8ae6
...
@@ -59,19 +59,45 @@
...
@@ -59,19 +59,45 @@
</li>
</li>
</ul>
</ul>
<!-- Default dropup button -->
<div
class=
"row"
>
<div
class=
"btn-group dropup"
style=
"margin-top: 60px;"
>
<div
class=
"col-sm-12 mt-4"
>
<button
type=
"button"
class=
"btn btn-secondary"
>
Dropup
</button>
<!-- Default dropup button -->
<button
type=
"button"
class=
"btn btn-secondary dropdown-toggle"
data-toggle=
"dropdown"
aria-haspopup=
"true"
aria-expanded=
"false"
>
<div
class=
"btn-group dropup"
>
<span
class=
"sr-only"
>
Toggle Dropdown
</span>
<button
type=
"button"
class=
"btn btn-secondary"
>
Dropup
</button>
</button>
<button
type=
"button"
class=
"btn btn-secondary dropdown-toggle"
data-toggle=
"dropdown"
aria-haspopup=
"true"
aria-expanded=
"false"
>
<div
class=
"dropdown-menu"
>
<span
class=
"sr-only"
>
Toggle Dropdown
</span>
<a
class=
"dropdown-item"
href=
"#"
>
Action
</a>
</button>
<a
class=
"dropdown-item"
href=
"#"
>
Another action
</a>
<div
class=
"dropdown-menu"
>
<a
class=
"dropdown-item"
href=
"#"
>
Something else here
</a>
<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>
</div>
</div>
<script
src=
"../../../docs/assets/js/vendor/jquery-slim.min.js"
></script>
<script
src=
"../../../docs/assets/js/vendor/jquery-slim.min.js"
></script>
<script
src=
"../../../docs/assets/js/vendor/popper.min.js"
></script>
<script
src=
"../../../docs/assets/js/vendor/popper.min.js"
></script>
...
...
This diff is collapsed.
Click to expand it.
scss/_dropdown.scss
+
0
-
14
View file @
b36d8ae6
...
@@ -108,20 +108,6 @@
...
@@ -108,20 +108,6 @@
}
}
}
}
// Menu positioning
//
// Add extra class to `.dropdown-menu` to flip the alignment of the dropdown
// menu with the parent.
.dropdown-menu-right
{
right
:
0
;
left
:
auto
!
important
;
// Reset the default from `.dropdown-menu`
}
.dropdown-menu-left
{
right
:
auto
!
important
;
left
:
0
;
}
.dropdown-menu.show
{
.dropdown-menu.show
{
display
:
block
;
display
:
block
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets