diff --git a/packages/dropdown-item/index.js b/packages/dropdown-item/index.js
index 4797b711b..28b7e5c75 100644
--- a/packages/dropdown-item/index.js
+++ b/packages/dropdown-item/index.js
@@ -55,7 +55,15 @@ export default sfc({
},
render(h) {
- const { top, zIndex, overlay, duration, activeColor, closeOnClickOverlay } = this.parent;
+ const {
+ zIndex,
+ offset,
+ overlay,
+ duration,
+ direction,
+ activeColor,
+ closeOnClickOverlay
+ } = this.parent;
const Options = this.options.map(option => {
const active = option.value === this.value;
@@ -81,11 +89,18 @@ export default sfc({
const emit = eventName => () => this.$emit(eventName);
+ const style = { zIndex };
+ if (direction === 'down') {
+ style.top = `${offset}px`;
+ } else {
+ style.bottom = `${offset}px`;
+ }
+
return (
-
+
+
+
+
+
+
+
+
+
+
+
+```
+
+### Disabled
+
+```html
+
+
+
+
+```
+
## API
### DropdownMenu Props
@@ -85,6 +103,7 @@ export default {
| active-color | Active color of title and option | `String` | `#1989fa` |
| z-index | z-index of menu item | `Number` | `10` |
| duration | Transition duration, unit second | `Number` | `0.2` |
+| direction | Expand direction, can be set to `up` | `String` | `down` |
| overlay | Whether to show overlay | `Boolean` | `true` |
| close-on-click-overlay | Whether to close when click overlay | `Boolean` | `true` |
diff --git a/packages/dropdown-menu/index.js b/packages/dropdown-menu/index.js
index 5e2201c8b..805a15df4 100644
--- a/packages/dropdown-menu/index.js
+++ b/packages/dropdown-menu/index.js
@@ -6,10 +6,13 @@ import { ClickOutsideMixin } from '../mixins/click-outside';
const [sfc, bem] = use('dropdown-menu');
export default sfc({
- mixins: [ParentMixin('vanDropdownMenu'), ClickOutsideMixin({
- event: 'click',
- method: 'onClickOutside'
- })],
+ mixins: [
+ ParentMixin('vanDropdownMenu'),
+ ClickOutsideMixin({
+ event: 'click',
+ method: 'onClickOutside'
+ })
+ ],
props: {
overlay: {
@@ -24,6 +27,10 @@ export default sfc({
type: Number,
default: 0.2
},
+ direction: {
+ type: String,
+ default: 'down'
+ },
activeColor: {
type: String,
default: BLUE
@@ -36,7 +43,7 @@ export default sfc({
data() {
return {
- top: 0
+ offset: 0
};
},
@@ -44,7 +51,12 @@ export default sfc({
toggleItem(active) {
const { menu } = this.$refs;
const rect = menu.getBoundingClientRect();
- this.top = rect.bottom;
+
+ if (this.direction === 'down') {
+ this.offset = rect.bottom;
+ } else {
+ this.offset = window.innerHeight - rect.top;
+ }
this.children.forEach((item, index) => {
if (index === active) {
@@ -75,7 +87,12 @@ export default sfc({
}}
>
{item.displayTitle}
diff --git a/packages/dropdown-menu/index.less b/packages/dropdown-menu/index.less
index a362c188b..1d92197bb 100644
--- a/packages/dropdown-menu/index.less
+++ b/packages/dropdown-menu/index.less
@@ -38,15 +38,14 @@
border: 3px solid;
border-color: transparent transparent currentColor currentColor;
transform: rotate(-45deg);
- opacity: .6;
+ opacity: .8;
content: '';
}
- &--active {
+ &--down {
&::after {
top: 7px;
transform: rotate(135deg);
- opacity: 1;
}
}
}
diff --git a/packages/dropdown-menu/test/__snapshots__/demo.spec.js.snap b/packages/dropdown-menu/test/__snapshots__/demo.spec.js.snap
index b1c503b91..606a04400 100644
--- a/packages/dropdown-menu/test/__snapshots__/demo.spec.js.snap
+++ b/packages/dropdown-menu/test/__snapshots__/demo.spec.js.snap
@@ -6,10 +6,10 @@ exports[`renders demo correctly 1`] = `