Skip to content
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

feat(components): [dropdown] add props for teleported API #10012

Merged
merged 1 commit into from Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/en-US/component/dropdown.md
Expand Up @@ -95,6 +95,7 @@ dropdown/sizes
| tabindex | [tabindex](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex) of Dropdown | number | — | 0 |
| popper-class | custom class name for Dropdown's dropdown | string | — | — |
| popper-options | [popper.js](https://popper.js.org/docs/v2/) parameters | Object | refer to [popper.js](https://popper.js.org/docs/v2/) doc | `{modifiers: [{name: 'computeStyles',options: {gpuAcceleration: false}}]}` |
| teleported | whether the dropdown popup is teleported to the body | boolean | — | true |

## Dropdown Slots

Expand Down
63 changes: 62 additions & 1 deletion packages/components/dropdown/__tests__/dropdown.test.ts
@@ -1,11 +1,12 @@
// @ts-nocheck
import { nextTick } from 'vue'
import { mount } from '@vue/test-utils'
import { describe, expect, test, vi } from 'vitest'
import { afterEach, describe, expect, test, vi } from 'vitest'
import { rAF } from '@element-plus/test-utils/tick'
import { EVENT_CODE } from '@element-plus/constants'
import { ElTooltip } from '@element-plus/components/tooltip'
import Button from '@element-plus/components/button'
import { POPPER_CONTAINER_SELECTOR } from '@element-plus/hooks'
import Dropdown from '../src/dropdown.vue'
import DropdownItem from '../src/dropdown-item.vue'
import DropdownMenu from '../src/dropdown-menu.vue'
Expand All @@ -28,6 +29,10 @@ const _mount = (template: string, data, otherObj?) =>
})

describe('Dropdown', () => {
afterEach(() => {
document.body.innerHTML = ''
})

test('create', async () => {
const wrapper = _mount(
`
Expand Down Expand Up @@ -756,4 +761,60 @@ describe('Dropdown', () => {
expect(menuItem.attributes()['role']).toBe('button')
})
})

describe('teleported API', () => {
test('should mount on popper container', async () => {
expect(document.body.innerHTML).toBe('')
_mount(
`
<el-dropdown ref="b" placement="right">
<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>`,
() => ({})
)

await nextTick()
expect(
document.body.querySelector(POPPER_CONTAINER_SELECTOR).innerHTML
).not.toBe('')
})

test('should not mount on the popper container', async () => {
expect(document.body.innerHTML).toBe('')
_mount(
`
<el-dropdown ref="b" placement="right" :teleported="false">
<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>`,
() => ({})
)

await nextTick()
expect(
document.body.querySelector(POPPER_CONTAINER_SELECTOR).innerHTML
).toBe('')
})
})
})
1 change: 1 addition & 0 deletions packages/components/dropdown/src/dropdown.ts
Expand Up @@ -87,6 +87,7 @@ export const dropdownProps = buildProps({
buttonProps: {
type: definePropType<ButtonProps>(Object),
},
teleported: useTooltipContentProps.teleported,
} as const)

export const dropdownItemProps = buildProps({
Expand Down
2 changes: 1 addition & 1 deletion packages/components/dropdown/src/dropdown.vue
Expand Up @@ -21,7 +21,7 @@
:virtual-triggering="splitButton"
:disabled="disabled"
:transition="`${ns.namespace.value}-zoom-in-top`"
teleported
:teleported="teleported"
pure
persistent
@before-show="handleBeforeShowTooltip"
Expand Down