-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support sub-menu for dropdown #1455
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
57a8329
Add submenu component
jonahtanjz d0942f5
Add submenu functions and styling
jonahtanjz 1fd3231
Add highlighting for submenu containing current page
jonahtanjz be946d0
Prevent overflow of submenu
jonahtanjz 7164878
Open submenu on hover
jonahtanjz a26f606
Revert tests
jonahtanjz 969a96f
Update after review
jonahtanjz e6fa314
Update tests
jonahtanjz 4bc69a2
Add method in submenu
jonahtanjz bcb7af3
Update after review
jonahtanjz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
<template> | ||
<li | ||
ref="submenu" | ||
:class="[addClass, 'dropdown-submenu', | ||
{ 'dropright': dropright, 'dropleft': dropleft }]" | ||
> | ||
<slot name="button"> | ||
<a | ||
class="submenu-toggle" | ||
role="button" | ||
:class="{disabled: disabled}" | ||
> | ||
<slot name="_header"> | ||
<slot name="header"></slot> | ||
</slot> | ||
</a> | ||
</slot> | ||
<slot name="dropdown-menu"> | ||
<ul class="dropdown-menu"> | ||
<slot></slot> | ||
</ul> | ||
</slot> | ||
</li> | ||
</template> | ||
|
||
<script> | ||
import { toBoolean } from './utils/utils'; | ||
import $ from './utils/NodeList'; | ||
import positionSubmenu from './utils/submenu'; | ||
|
||
export default { | ||
props: { | ||
addClass: { | ||
type: String, | ||
default: '', | ||
}, | ||
disabled: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
}, | ||
data() { | ||
return { | ||
show: false, | ||
dropright: true, | ||
dropleft: false, | ||
}; | ||
}, | ||
computed: { | ||
disabledBool() { | ||
return toBoolean(this.disabled); | ||
}, | ||
}, | ||
methods: { | ||
hideSubmenu() { | ||
this.show = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated :) |
||
$(this.$refs.submenu).findChildren('ul').each(ul => ul.classList.toggle('show', false)); | ||
this.alignMenuRight(); | ||
}, | ||
showSubmenu() { | ||
this.show = true; | ||
$(this.$refs.submenu).findChildren('ul').each((ul) => { | ||
ul.classList.toggle('show', true); | ||
if (positionSubmenu.isRightAlign(ul)) { | ||
this.alignMenuRight(); | ||
} else { | ||
this.alignMenuLeft(); | ||
} | ||
positionSubmenu.preventOverflow(ul); | ||
}); | ||
}, | ||
alignMenuRight() { | ||
this.dropright = true; | ||
this.dropleft = false; | ||
}, | ||
alignMenuLeft() { | ||
this.dropright = false; | ||
this.dropleft = true; | ||
}, | ||
}, | ||
mounted() { | ||
const $el = $(this.$refs.submenu); | ||
if (this.show) { | ||
this.showSubmenu(); | ||
} | ||
$el.onBlur(() => { this.hideSubmenu(); }, false); | ||
$el.findChildren('a,button').on('click', (e) => { | ||
e.preventDefault(); | ||
if (e.target !== e.currentTarget) { e.stopPropagation(); } | ||
if (window.innerWidth < 768) { | ||
if (this.disabledBool) { return false; } | ||
if (this.show) { | ||
this.hideSubmenu(); | ||
} else { | ||
this.showSubmenu(); | ||
} | ||
} | ||
return false; | ||
}); | ||
$el.findChildren('a,button').on('mouseover', (e) => { | ||
e.preventDefault(); | ||
if (window.innerWidth > 767) { | ||
if (this.disabledBool) { return false; } | ||
e.currentTarget.click(); | ||
this.showSubmenu(); | ||
} | ||
return false; | ||
}); | ||
}, | ||
beforeDestroy() { | ||
const $el = $(this.$refs.submenu); | ||
$el.offBlur(); | ||
$el.findChildren('a,button').off(); | ||
$el.findChildren('ul').off(); | ||
}, | ||
}; | ||
</script> | ||
|
||
<style scoped> | ||
.dropdown-submenu { | ||
color: #212529 !important; | ||
padding: 0 !important; | ||
position: relative; | ||
} | ||
|
||
.submenu-toggle { | ||
display: inline-block; | ||
width: 100%; | ||
padding: .25rem .75rem .25rem 1.5rem; | ||
} | ||
|
||
.dropdown > ul > .dropdown-submenu:last-child > ul, | ||
.btn-group > ul > .dropdown-submenu:last-child > ul { | ||
margin-bottom: -.5rem; | ||
} | ||
|
||
@media (min-width: 768px) { | ||
.submenu-toggle:after { | ||
display: inline-block; | ||
width: 0; | ||
height: 0; | ||
vertical-align: .255em; | ||
content: ""; | ||
border-top: .3em solid transparent; | ||
border-right: 0; | ||
border-bottom: .3em solid transparent; | ||
border-left: .3em solid; | ||
float: right; | ||
margin-top: .5em; | ||
} | ||
} | ||
|
||
@media (max-width: 767px) { | ||
.dropdown-submenu > ul { | ||
padding-bottom: 0; | ||
border-radius: 0; | ||
margin: -.05rem; | ||
position: static; | ||
float: none; | ||
} | ||
|
||
.submenu-toggle:after { | ||
display: inline-block; | ||
width: 0; | ||
height: 0; | ||
margin-left: .255em; | ||
vertical-align: .255em; | ||
content: ""; | ||
border-top: .3em solid; | ||
border-right: .3em solid transparent; | ||
border-bottom: 0; | ||
border-left: .3em solid transparent; | ||
float: right; | ||
margin-top: .5em; | ||
} | ||
} | ||
</style> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's correct these in another PR; we could enable linting for
dropdown.vue
as well. (the unlinted ones are files that haven't changed much from vue-strap)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright sure will open another PR for this 👍