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: Popover add contextmenu #2166

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/popover/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface PopoverProps {
title?: string | JSX.Element
content: string | JSX.Element
placement?: 'top' | 'right' | 'bottom' | 'left'
trigger?: 'click' | 'focus' | 'hover'
trigger?: 'click' | 'focus' | 'hover' | 'contextmenu'
visible?: boolean
style?: React.CSSProperties
className?: string
Expand Down
14 changes: 13 additions & 1 deletion components/popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class Popover extends Component {
}
static propTypes = {
placement: PropTypes.oneOf(['top', 'bottom', 'left', 'right']),
trigger: PropTypes.oneOf(['click', 'focus', 'hover']),
trigger: PropTypes.oneOf(['click', 'focus', 'hover', 'contextmenu']),
title: PropTypes.oneOfType([PropTypes.node, PropTypes.string]),
content: PropTypes.oneOfType([PropTypes.node, PropTypes.string]),
width: PropTypes.string
Expand Down Expand Up @@ -112,6 +112,18 @@ export default class Popover extends Component {
this.delayHidePopper(e)
clearTimeout(this.delayShowPopperTimer)
})
} else if (trigger === 'contextmenu') {
referenceRef.addEventListener('contextmenu', (e) => {
e.preventDefault()
this.state.showPopper ? this.hidePopper() : this.showPopper()
})

document.addEventListener('click', (e) => {
this.eventTarget = e.target
if (this.isInPopover()) return

this.hidePopper()
})
}
}
render() {
Expand Down
3 changes: 3 additions & 0 deletions docs/demo/popover/section-base.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class Demo extends React.Component {
<Popover title={title} content={content} style={{margin: '10px 10px'}} placement="left" trigger="click">
<Button type="danger">Popover Left</Button>
</Popover>
<Popover title={title} content={content} style={{margin: '10px 10px'}} placement="bottom" trigger="contextmenu">
<Button>contextmenu触发</Button>
</Popover>
</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion docs/zh-CN/components/popover.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ import DemoMix from "../../demo/popover/section-mix.jsx";
| title | 气泡卡片标题 | string | - | - |
| content | 气泡卡片内容 | string \| ReactNode | - | - |
| placement | 气泡卡片显示的位置 | string | 'top' \| 'right' \| 'bottom' \| 'left' | 'top' |
| trigger | 气泡卡片触发方式 | string | 'click' \| 'focus' \| 'hover' | 'click' |
| trigger | 气泡卡片触发方式 | string | 'click' \| 'focus' \| 'hover' \| 'contextmenu' | 'click' |
| visible | 控制气泡卡片的显示和隐藏(需要组件完全受控时使用) | boolean | true \| false | - |
| overlayClassName | 下拉根元素的类名称 (3.0 新增) | string | - | - |