Skip to content

Commit fc49325

Browse files
authored
fix(dropdown): use class position-static instead of inline style (bootstrap-vue#1451)
1 parent 117e68f commit fc49325

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

src/components/dropdown/dropdown.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default {
7373
)
7474
return h(
7575
'div',
76-
{ attrs: { id: t.safeId() }, class: t.dropdownClasses, style: t.dropdownStyles },
76+
{ attrs: { id: t.safeId() }, class: t.dropdownClasses },
7777
[ split, toggle, menu ]
7878
)
7979
},
@@ -111,24 +111,21 @@ export default {
111111
},
112112
computed: {
113113
dropdownClasses () {
114+
let position = ''
115+
// Position `static` is needed to allow menu to "breakout" of the scrollParent boundaries
116+
// See https://github.com/twbs/bootstrap/issues/24251#issuecomment-341413786
117+
if (this.boundary === 'scrollParent' || !this.boundary) {
118+
position = 'position-static'
119+
}
114120
return [
115121
'btn-group',
116122
'b-dropdown',
117123
'dropdown',
118124
this.dropup ? 'dropup' : '',
119-
this.visible ? 'show' : ''
125+
this.visible ? 'show' : '',
126+
position
120127
]
121128
},
122-
dropdownStyles () {
123-
// Position `static` is needed to allow menu to "breakout" of the scrollParent boundaries
124-
// See https://github.com/twbs/bootstrap/issues/24251#issuecomment-341413786
125-
if (this.boundary === 'scrollParent' || !this.boundary) {
126-
return {}
127-
}
128-
// We enable this feature only when the user supplies a boundary other than `scrollParent`
129-
// to preserve default functionality
130-
return { position: 'static' }
131-
},
132129
menuClasses () {
133130
return [
134131
'dropdown-menu',

src/components/dropdown/dropdown.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,21 @@ describe('dropdown', async () => {
5858
.find(node => node.tagName === 'BUTTON' && node.id === `${dd_8.safeId('_BV_toggle_')}`)
5959
expect(toggle).toHaveClass('dropdown-toggle')
6060
})
61+
/*
62+
it('boundary set to viewport should have class position-static', async () => {
63+
const {app: {$refs}} = window
64+
const {dd_9} = $refs
65+
66+
expect(dd_9).toHaveClass('position-static')
67+
})
6168
69+
it('boundary not set should not have class position-static', async () => {
70+
const {app: {$refs}} = window
71+
const {dd_1} = $refs
72+
73+
expect(dd_1).not.toHaveClass('position-static')
74+
})
75+
*/
6276
it('dd-item should render as link by default', async () => {
6377
const {app: {$refs}} = window
6478
const {dd_6} = $refs

src/components/dropdown/fixtures/dropdown.html

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
<b-dropdown-item href="#">Something else here</b-dropdown-item>
1010
</b-dropdown>
1111

12-
<br>
13-
<br>
12+
<br><br>
1413

1514
<b-dropdown ref="dd_2"
1615
text="Split Dropdown Button"
@@ -22,8 +21,7 @@
2221
<b-dropdown-item href="#">Something else here...</b-dropdown-item>
2322
</b-dropdown>
2423

25-
<br>
26-
<br>
24+
<br><br>
2725

2826
<b-dropdown ref="dd_3"
2927
text="Right align"
@@ -35,8 +33,7 @@
3533
<b-dropdown-item href="#">Something else here</b-dropdown-item>
3634
</b-dropdown>
3735

38-
<br>
39-
<br>
36+
<br><br>
4037

4138
<b-dropdown ref="dd_4"
4239
text="Drop-Up"
@@ -48,8 +45,7 @@
4845
<b-dropdown-item href="#">Something else here</b-dropdown-item>
4946
</b-dropdown>
5047

51-
<br>
52-
<br>
48+
<br><br>
5349

5450
<b-dd ref="dd_5"
5551
text="Link"
@@ -68,6 +64,8 @@
6864
<b-dropdown-divider></b-dropdown-divider>
6965
</b-dropdown>
7066

67+
<br><br>
68+
7169
<b-dropdown ref="dd_7" text="Dropdown" variant="link" no-caret>
7270
<template slot="button-content">
7371
<span>icon</span>
@@ -78,9 +76,18 @@
7876
<b-dropdown-item href="#">Something else here...</b-dropdown-item>
7977
</b-dropdown>
8078

79+
<br><br>
80+
8181
<b-dropdown ref="dd_8" text="Dropdown" no-caret split>
8282
<b-dropdown-item href="#">Action</b-dropdown-item>
8383
<b-dropdown-item href="#">Another action</b-dropdown-item>
8484
<b-dropdown-item href="#">Something else here...</b-dropdown-item>
8585
</b-dropdown>
86+
87+
<br><br>
88+
89+
<b-dropdown ref="dd_9" text="Dropdown" boundary="viewport">
90+
<b-dropdown-item href="#">Action</b-dropdown-item>
91+
<b-dropdown-item href="#">Another action</b-dropdown-item>
92+
</b-dropdown>
8693
</div>

0 commit comments

Comments
 (0)