mirror of
https://github.com/element-plus/element-plus.git
synced 2024-12-27 03:01:14 +08:00
feat(dropdown): add max-height prop of menu (#1436)
* feat(dropdown): add max-height prop of menu * feat: delete demo
This commit is contained in:
parent
76c7acb87a
commit
d7341b0fec
@ -313,6 +313,30 @@ describe('Dropdown', () => {
|
|||||||
})
|
})
|
||||||
await sleep(TIMEOUT)
|
await sleep(TIMEOUT)
|
||||||
expect(wrapper.findComponent({ ref: 'd' }).attributes('tabindex')).toBe('0')
|
expect(wrapper.findComponent({ ref: 'd' }).attributes('tabindex')).toBe('0')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('max height', async () => {
|
||||||
|
const wrapper = _mount(
|
||||||
|
`
|
||||||
|
<el-dropdown ref="b" max-height="60px">
|
||||||
|
<span class="el-dropdown-link" ref="a">
|
||||||
|
dropdown<i class="el-icon-arrow-down el-icon--right"></i>
|
||||||
|
</span>
|
||||||
|
<template #dropdown>
|
||||||
|
<el-dropdown-menu>
|
||||||
|
<el-dropdown-item>Apple</el-dropdown-item>
|
||||||
|
<el-dropdown-item>Orange</el-dropdown-item>
|
||||||
|
<el-dropdown-item>Cherry</el-dropdown-item>
|
||||||
|
<el-dropdown-item disabled>Peach</el-dropdown-item>
|
||||||
|
<el-dropdown-item divided>Pear</el-dropdown-item>
|
||||||
|
</el-dropdown-menu>
|
||||||
|
</template>
|
||||||
|
</el-dropdown>
|
||||||
|
`,
|
||||||
|
() => ({}),
|
||||||
|
)
|
||||||
|
const content = wrapper.findComponent({ ref: 'b' })
|
||||||
|
const scrollbar = content.findComponent({ ref: 'scrollbar' })
|
||||||
|
expect(scrollbar.find('.el-scrollbar__wrap').attributes('style')).toContain('max-height: 60px;')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -14,11 +14,18 @@
|
|||||||
:gpu-acceleration="false"
|
:gpu-acceleration="false"
|
||||||
>
|
>
|
||||||
<template #default>
|
<template #default>
|
||||||
<slot name="dropdown"></slot>
|
<el-scrollbar
|
||||||
|
ref="scrollbar"
|
||||||
|
tag="ul"
|
||||||
|
:wrap-style="wrapStyle"
|
||||||
|
view-class="el-dropdown__list"
|
||||||
|
>
|
||||||
|
<slot name="dropdown"></slot>
|
||||||
|
</el-scrollbar>
|
||||||
</template>
|
</template>
|
||||||
<template #trigger>
|
<template #trigger>
|
||||||
<div :class="['el-dropdown', dropdownSize ? 'el-dropdown--' + dropdownSize : '']">
|
<div :class="['el-dropdown', dropdownSize ? 'el-dropdown--' + dropdownSize : '']">
|
||||||
<slot v-if="!splitButton" name="default"> </slot>
|
<slot v-if="!splitButton" name="default"></slot>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<el-button-group>
|
<el-button-group>
|
||||||
<el-button
|
<el-button
|
||||||
@ -55,14 +62,17 @@ import {
|
|||||||
import { on, addClass, removeClass } from '@element-plus/utils/dom'
|
import { on, addClass, removeClass } from '@element-plus/utils/dom'
|
||||||
import ElButton from '@element-plus/button'
|
import ElButton from '@element-plus/button'
|
||||||
import ElButtonGroup from '@element-plus/button-group'
|
import ElButtonGroup from '@element-plus/button-group'
|
||||||
|
import ElScrollbar from '@element-plus/scrollbar'
|
||||||
import ElPopper from '@element-plus/popper'
|
import ElPopper from '@element-plus/popper'
|
||||||
import { useDropdown } from './useDropdown'
|
import { useDropdown } from './useDropdown'
|
||||||
|
import { addUnit } from '@element-plus/utils/util'
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'ElDropdown',
|
name: 'ElDropdown',
|
||||||
components: {
|
components: {
|
||||||
ElButton,
|
ElButton,
|
||||||
ElButtonGroup,
|
ElButtonGroup,
|
||||||
|
ElScrollbar,
|
||||||
ElPopper,
|
ElPopper,
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
@ -100,6 +110,10 @@ export default defineComponent({
|
|||||||
type: String,
|
type: String,
|
||||||
default: 'light',
|
default: 'light',
|
||||||
},
|
},
|
||||||
|
maxHeight: {
|
||||||
|
type: [Number, String],
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
emits: ['visible-change', 'click', 'command'],
|
emits: ['visible-change', 'click', 'command'],
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
@ -109,6 +123,9 @@ export default defineComponent({
|
|||||||
const timeout = ref<Nullable<number>>(null)
|
const timeout = ref<Nullable<number>>(null)
|
||||||
|
|
||||||
const visible = ref(false)
|
const visible = ref(false)
|
||||||
|
const scrollbar = ref(null)
|
||||||
|
const wrapStyle = computed(() => `max-height: ${addUnit(props.maxHeight)}`)
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => visible.value,
|
() => visible.value,
|
||||||
val => {
|
val => {
|
||||||
@ -187,11 +204,13 @@ export default defineComponent({
|
|||||||
function triggerElmFocus() {
|
function triggerElmFocus() {
|
||||||
triggerElm.value?.focus?.()
|
triggerElm.value?.focus?.()
|
||||||
}
|
}
|
||||||
|
|
||||||
function triggerElmBlur() {
|
function triggerElmBlur() {
|
||||||
triggerElm.value?.blur?.()
|
triggerElm.value?.blur?.()
|
||||||
}
|
}
|
||||||
|
|
||||||
const dropdownSize = computed(() => props.size || ELEMENT.size)
|
const dropdownSize = computed(() => props.size || ELEMENT.size)
|
||||||
|
|
||||||
function commandHandler(...args) {
|
function commandHandler(...args) {
|
||||||
emit('command', ...args)
|
emit('command', ...args)
|
||||||
}
|
}
|
||||||
@ -247,6 +266,8 @@ export default defineComponent({
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
visible,
|
visible,
|
||||||
|
scrollbar,
|
||||||
|
wrapStyle,
|
||||||
dropdownSize,
|
dropdownSize,
|
||||||
handlerMainButtonClick,
|
handlerMainButtonClick,
|
||||||
triggerVnode,
|
triggerVnode,
|
||||||
|
@ -741,6 +741,7 @@ $--tree-expand-icon-color: $--color-text-placeholder !default;
|
|||||||
$--dropdown-menu-box-shadow: $--box-shadow-light !default;
|
$--dropdown-menu-box-shadow: $--box-shadow-light !default;
|
||||||
$--dropdown-menuItem-hover-fill: $--color-primary-light-9 !default;
|
$--dropdown-menuItem-hover-fill: $--color-primary-light-9 !default;
|
||||||
$--dropdown-menuItem-hover-color: $--link-color !default;
|
$--dropdown-menuItem-hover-color: $--link-color !default;
|
||||||
|
$--dropdown-menu-index: 10 !default;
|
||||||
|
|
||||||
/* Badge
|
/* Badge
|
||||||
-------------------------- */
|
-------------------------- */
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
// using attributes selector to override
|
// using attributes selector to override
|
||||||
|
|
||||||
@include picker-popper(
|
@include picker-popper(
|
||||||
$--color-white,
|
$--color-white,
|
||||||
1px solid $--border-color-light,
|
1px solid $--border-color-light,
|
||||||
$--dropdown-menu-box-shadow,
|
$--dropdown-menu-box-shadow,
|
||||||
);
|
);
|
||||||
|
|
||||||
.#{$namespace}-dropdown-menu {
|
.#{$namespace}-dropdown-menu {
|
||||||
@ -25,10 +25,22 @@
|
|||||||
#{& + '-selfdefine'} {
|
#{& + '-selfdefine'} {
|
||||||
outline: none;
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@include b(scrollbar__bar) {
|
||||||
|
z-index: #{$--dropdown-menu-index + 1};
|
||||||
|
}
|
||||||
|
|
||||||
|
@include b(dropdown__list) {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.#{$namespace}-button-group {
|
.#{$namespace}-button-group {
|
||||||
display: block;
|
display: block;
|
||||||
|
|
||||||
.#{$namespace}-button {
|
.#{$namespace}-button {
|
||||||
float: none;
|
float: none;
|
||||||
}
|
}
|
||||||
@ -82,7 +94,7 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
z-index: 10;
|
z-index: $--dropdown-menu-index;
|
||||||
padding: 10px 0;
|
padding: 10px 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
background-color: $--color-white;
|
background-color: $--color-white;
|
||||||
|
@ -306,12 +306,12 @@ Besides default size, Dropdown component provides three additional sizes for you
|
|||||||
```
|
```
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
|
||||||
### Dropdown Attributes
|
### Dropdown Attributes
|
||||||
| Attribute | Description | Type | Accepted Values | Default |
|
| Attribute | Description | Type | Accepted Values | Default |
|
||||||
|------------- |---------------- |---------------- |---------------------- |-------- |
|
|------------- |---------------- |---------------- |---------------------- |-------- |
|
||||||
| type | menu button type, refer to `Button` Component, only works when `split-button` is true | string | — | — |
|
| type | menu button type, refer to `Button` Component, only works when `split-button` is true | string | — | — |
|
||||||
| size | menu size, also works on the split button | string | medium / small / mini | — |
|
| size | menu size, also works on the split button | string | medium / small / mini | — |
|
||||||
|
| max-height | the max height of menu | string / number | — | — |
|
||||||
| split-button | whether a button group is displayed | boolean | — | false |
|
| split-button | whether a button group is displayed | boolean | — | false |
|
||||||
| placement | placement of pop menu | string | top/top-start/top-end/bottom/bottom-start/bottom-end | bottom-end |
|
| placement | placement of pop menu | string | top/top-start/top-end/bottom/bottom-start/bottom-end | bottom-end |
|
||||||
| trigger | how to trigger | string | hover/click/contextmenu | hover |
|
| trigger | how to trigger | string | hover/click/contextmenu | hover |
|
||||||
|
@ -307,12 +307,12 @@ Además del tamaño predeterminado, el componente Dropdown proporciona tres tama
|
|||||||
```
|
```
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
|
||||||
### Dropdown atributos
|
### Dropdown atributos
|
||||||
| Atributo | Descripción | Tipo | Valores aceptados | Por defecto |
|
| Atributo | Descripción | Tipo | Valores aceptados | Por defecto |
|
||||||
| ------------- | ---------------------------------------- | ------- | ---------------------------------------- | ----------- |
|
| ------------- | ---------------------------------------- | ------- | ---------------------------------------- | ----------- |
|
||||||
| type | tipo de botón de menú, consulte Componente`Button`, sólo funciona cuando `split-button` es true. | string | — | — |
|
| type | tipo de botón de menú, consulte Componente`Button`, sólo funciona cuando `split-button` es true. | string | — | — |
|
||||||
| size | tamaño del menú, también funciona en `split-button` | string | medium / small / mini | — |
|
| size | tamaño del menú, también funciona en `split-button` | string | medium / small / mini | — |
|
||||||
|
| max-height | the max height of menu | string / number | — | — |
|
||||||
| split-button | si se visualiza un grupo de botones | boolean | — | false |
|
| split-button | si se visualiza un grupo de botones | boolean | — | false |
|
||||||
| placement | colocación del menú | string | top/top-start/top-end/bottom/bottom-start/bottom-end | bottom-end |
|
| placement | colocación del menú | string | top/top-start/top-end/bottom/bottom-start/bottom-end | bottom-end |
|
||||||
| trigger | cómo detonar | string | hover/click/contextmenu | hover |
|
| trigger | cómo detonar | string | hover/click/contextmenu | hover |
|
||||||
|
@ -306,13 +306,13 @@ En plus de la taille par défaut, le composant Dropdown propose trois autres tai
|
|||||||
```
|
```
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
|
||||||
### Attributs du Dropdown
|
### Attributs du Dropdown
|
||||||
|
|
||||||
| Attribut | Description | Type | Valeurs acceptées | Défaut |
|
| Attribut | Description | Type | Valeurs acceptées | Défaut |
|
||||||
|------------- |---------------- |---------------- |---------------------- |-------- |
|
|------------- |---------------- |---------------- |---------------------- |-------- |
|
||||||
| type | Type du bouton, se référer au composant `Button`. Ne marche que si `split-button` est `true`. | string | — | — |
|
| type | Type du bouton, se référer au composant `Button`. Ne marche que si `split-button` est `true`. | string | — | — |
|
||||||
| size | Taille du menu, marche aussi avec `split button`. | string | medium / small / mini | — |
|
| size | Taille du menu, marche aussi avec `split button`. | string | medium / small / mini | — |
|
||||||
|
| max-height | the max height of menu | string / number | — | — |
|
||||||
| split-button | Si le bouton est séparé en deux. | boolean | — | false |
|
| split-button | Si le bouton est séparé en deux. | boolean | — | false |
|
||||||
| placement | Emplacement du menu déroulant | string | top/top-start/top-end/bottom/bottom-start/bottom-end | bottom-end |
|
| placement | Emplacement du menu déroulant | string | top/top-start/top-end/bottom/bottom-start/bottom-end | bottom-end |
|
||||||
| trigger | Comment déclencher l'ouverture du menu. | string | hover/click/contextmenu | hover |
|
| trigger | Comment déclencher l'ouverture du menu. | string | hover/click/contextmenu | hover |
|
||||||
|
@ -305,12 +305,12 @@ dropdownリストを起動するには、ボタンを使用します。
|
|||||||
```
|
```
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
|
||||||
### dropdown属性
|
### dropdown属性
|
||||||
| Attribute | Description | Type | Accepted Values | Default |
|
| Attribute | Description | Type | Accepted Values | Default |
|
||||||
|------------- |---------------- |---------------- |---------------------- |-------- |
|
|------------- |---------------- |---------------- |---------------------- |-------- |
|
||||||
| type | `split-button` が `true`のとき、メニューボタンのタイプは `Button` コンポーネントを参照する。 | string | — | — |
|
| type | `split-button` が `true`のとき、メニューボタンのタイプは `Button` コンポーネントを参照する。 | string | — | — |
|
||||||
| size | メニューのサイズ(分割ボタンでも動作) | string | medium / small / mini | — |
|
| size | メニューのサイズ(分割ボタンでも動作) | string | medium / small / mini | — |
|
||||||
|
| max-height | the max height of menu | string / number | — | — |
|
||||||
| split-button | ボタングループの表示の有無 | boolean | — | false |
|
| split-button | ボタングループの表示の有無 | boolean | — | false |
|
||||||
| placement | ポップメニューの配置 | string | top/top-start/top-end/bottom/bottom-start/bottom-end | bottom-end |
|
| placement | ポップメニューの配置 | string | top/top-start/top-end/bottom/bottom-start/bottom-end | bottom-end |
|
||||||
| trigger | トリガーのきっかけ | string | hover/click/contextmenu | hover |
|
| trigger | トリガーのきっかけ | string | hover/click/contextmenu | hover |
|
||||||
|
@ -315,6 +315,7 @@ Dropdown 组件提供除了默认值以外的三种尺寸,可以在不同场
|
|||||||
|------------- |---------------- |---------------- |---------------------- |-------- |
|
|------------- |---------------- |---------------- |---------------------- |-------- |
|
||||||
| type | 菜单按钮类型,同 Button 组件(只在`split-button`为 true 的情况下有效) | string | — | — |
|
| type | 菜单按钮类型,同 Button 组件(只在`split-button`为 true 的情况下有效) | string | — | — |
|
||||||
| size | 菜单尺寸,在`split-button`为 true 的情况下也对触发按钮生效 | string | medium / small / mini | — |
|
| size | 菜单尺寸,在`split-button`为 true 的情况下也对触发按钮生效 | string | medium / small / mini | — |
|
||||||
|
| max-height | 菜单最大高度 | string / number | — | — |
|
||||||
| split-button | 下拉触发元素呈现为按钮组 | boolean | — | false |
|
| split-button | 下拉触发元素呈现为按钮组 | boolean | — | false |
|
||||||
| placement | 菜单弹出位置 | string | top/top-start/top-end/bottom/bottom-start/bottom-end | bottom-end |
|
| placement | 菜单弹出位置 | string | top/top-start/top-end/bottom/bottom-start/bottom-end | bottom-end |
|
||||||
| trigger | 触发下拉的行为 | string | hover, click, contextmenu | hover |
|
| trigger | 触发下拉的行为 | string | hover, click, contextmenu | hover |
|
||||||
|
Loading…
Reference in New Issue
Block a user