-
Notifications
You must be signed in to change notification settings - Fork 332
feat(dropdown): add contextmenu trigger support #3861
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -93,9 +93,9 @@ export default { | |||||
| }, | ||||||
| desc: { | ||||||
| 'zh-CN': | ||||||
| '<p>通过 <code>trigger</code> 属性设置触发下拉的方式,默认为 <code>hover</code>。可选值为:<code>click</code> / <code>hover</code> 。</p>\n', | ||||||
| '<p>通过 <code>trigger</code> 属性设置触发下拉的方式,默认为 <code>hover</code>。可选值为:<code>click</code> / <code>hover</code> / <code>contextmenu</code>(3.28.0 起支持)。</p>\n', | ||||||
| 'en-US': | ||||||
| '<p>By setting the <code>trigger</code> attribute to trigger a drop-down, the default is <code>hover</code>. The optional values are: <code>click</code> / <code>hover</code>.</p>\n' | ||||||
| '<p>Use the <code>trigger</code> attribute to set how the dropdown is triggered. Default is <code>hover</code>. Optional values: <code>click</code> / <code>hover</code> / <code>contextmenu</code> (supported since 3.28.0).</p>\n' | ||||||
| }, | ||||||
| codeFiles: ['trigger.vue'] | ||||||
| }, | ||||||
|
|
@@ -108,7 +108,7 @@ export default { | |||||
| desc: { | ||||||
| 'zh-CN': '<p>通过 <code>visible</code> 属性手动控制下拉菜单显隐,优先级高于trigger。</p>\n', | ||||||
| 'en-US': | ||||||
| '<p>Manually control the visibility of the dropdown menu through the<code>visible</code>attribute, with priority over trigger.</p>\n' | ||||||
| '<p>Manually control the visibility of the dropdown menu through the <code>visible</code>attribute, with priority over trigger.</p>\n' | ||||||
|
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. Add missing space in the English description. There's a missing space between Apply this diff: - '<p>Manually control the visibility of the dropdown menu through the <code>visible</code>attribute, with priority over trigger.</p>\n'
+ '<p>Manually control the visibility of the dropdown menu through the <code>visible</code> attribute, with priority over trigger.</p>\n'📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| }, | ||||||
| codeFiles: ['visible.vue'] | ||||||
| }, | ||||||
|
|
@@ -307,7 +307,7 @@ export default { | |||||
| support: { | ||||||
| value: true | ||||||
| }, | ||||||
| description: '支持点击和悬停两种触发方式。', | ||||||
| description: '支持点击、悬停以及右键(contextmenu,3.28.0 起支持)触发方式。', | ||||||
| cloud: { | ||||||
| value: true | ||||||
| }, | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,7 @@ export const show = | |
| () => { | ||
| state.visible = true | ||
| }, | ||
| state.trigger === 'click' ? 0 : props.showTimeout | ||
| state.trigger === 'click' || state.trigger === 'contextmenu' ? 0 : props.showTimeout | ||
| ) | ||
| } | ||
| } | ||
|
|
@@ -82,7 +82,7 @@ export const hide = | |
| () => { | ||
| state.visible = false | ||
| }, | ||
| state.trigger === 'click' ? 0 : props.hideTimeout | ||
| state.trigger === 'click' || state.trigger === 'contextmenu' ? 0 : props.hideTimeout | ||
| ) | ||
| } | ||
| } | ||
|
|
@@ -127,7 +127,7 @@ export const handleItemKeyDown = | |
| ({ api, props, state, emit }: Pick<IDropdownRenderlessParams, 'api' | 'props' | 'state' | 'emit'>) => | ||
| (event: KeyboardEvent) => { | ||
| const keyCode = event.keyCode | ||
| const target = event.target | ||
| const target = event.target as HTMLElement | ||
| const currentIndex = state.menuItemsArray.indexOf(target) | ||
| const max = state.menuItemsArray.length - 1 | ||
|
|
||
|
|
@@ -215,7 +215,15 @@ export const initEvent = | |
| return | ||
| } | ||
|
|
||
| if (state.trigger === 'hover') { | ||
| /** --------------------------- | ||
| * 新增:右键触发 contextmenu | ||
| * --------------------------- */ | ||
| if (state.trigger === 'contextmenu') { | ||
|
Member
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. 你好,这个应该属于新特性了,需要在对应的api文件中添加描述和版本信息哈 |
||
| on(state.triggerElm, 'contextmenu', (e: MouseEvent) => { | ||
| e.preventDefault() | ||
| api.handleClick() | ||
| }) | ||
| } else if (state.trigger === 'hover') { | ||
|
Comment on lines
+218
to
+226
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. Memory leak: inline handler can't be removed in cleanup. The inline arrow function Recommended solution: Store the handler function to enable proper cleanup: +export const handleContextMenu =
+ ({ api }: Pick<IDropdownRenderlessParams, 'api'>) =>
+ (e: MouseEvent) => {
+ e.preventDefault()
+ api.handleClick()
+ }Then in the API object (where handlers are composed), add: const api = {
// ... other handlers
handleContextMenu: handleContextMenu({ api }),
// ...
}Update if (state.trigger === 'contextmenu') {
- on(state.triggerElm, 'contextmenu', (e: MouseEvent) => {
- e.preventDefault()
- api.handleClick()
- })
+ on(state.triggerElm, 'contextmenu', api.handleContextMenu)
} else if (state.trigger === 'hover') {Update - off(state.triggerElm, 'contextmenu', api.handleClick) /** 右键清理 */
+ off(state.triggerElm, 'contextmenu', api.handleContextMenu)🤖 Prompt for AI Agents |
||
| on(state.triggerElm, 'mouseenter', api.show) | ||
| on(state.triggerElm, 'mouseleave', api.hide) | ||
| on(state.dropdownElm, 'mouseenter', api.show) | ||
|
|
@@ -302,6 +310,7 @@ export const beforeDistory = | |
| off(state.triggerElm, 'mouseenter', api.show) | ||
| off(state.triggerElm, 'mouseleave', api.hide) | ||
| off(state.triggerElm, 'click', api.handleClick) | ||
| off(state.triggerElm, 'contextmenu', api.handleClick) /** 右键清理 */ | ||
| state.triggerElm = null | ||
| } | ||
|
|
||
|
|
||
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.
Fix incorrect variable references.
The
:iconbindings referencetinyIconPlus,tinyIconPlusCircle, etc., but these variables don't exist in the data properties (lines 60-66). This will cause runtime errors. Scenario 2 (lines 20-24) correctly usesiconPlus,iconPlusCircle, etc.Apply this diff to fix the variable references:
📝 Committable suggestion
🤖 Prompt for AI Agents