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

fix: Change background mouse click event to mousedown, mouseup #26 #27

Merged
merged 1 commit into from
Aug 9, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
transitionDuration: transition,
...mergeOptions?.styleModalContent
}"
@click.self="onClickDimmed"
@mousedown.self="onMouseDownDimmed"
@mouseup="onMouseUpDimmed"
>
<slot :emitClose="emitClose" />
<slot name="close" />
Expand Down Expand Up @@ -115,7 +116,7 @@ export default defineComponent({

const { latest } = useOrder({ modalRef, show })
useA11Y({ latest, modalRef, show })
const { onClickDimmed } = useClose({
const { onMouseDownDimmed, onMouseUpDimmed } = useClose({
close,
closeClickDimmed: mergeOptions.closeClickDimmed,
closeKeyCode: mergeOptions.closeKeyCode,
Expand Down Expand Up @@ -153,7 +154,8 @@ export default defineComponent({
latest,
mergeOptions,
modalRef,
onClickDimmed,
onMouseDownDimmed,
onMouseUpDimmed,
onTransitionEmit,
show,
teleportTarget,
Expand Down
17 changes: 13 additions & 4 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ type UseClose = ({ close, closeKeyCode, latest }: {
closeKeyCode: number | false;
latest: ComputedRef<boolean>;
}) => {
onClickDimmed: () => void
onMouseDownDimmed: (e: MouseEvent) => void
onMouseUpDimmed: (e: MouseEvent) => void
}

type UseOrder = ({ modalRef, show }: {
Expand Down Expand Up @@ -70,10 +71,17 @@ export const useA11Y: UseA11Y = ({ modalRef, latest, show }) => {
}

export const useClose: UseClose = ({ close, closeClickDimmed, closeKeyCode, latest }) => {
function onClickDimmed () {
if (closeClickDimmed) {
let actionTarget: null|EventTarget = null

function onMouseDownDimmed (e: MouseEvent) {
actionTarget = e.target
}

function onMouseUpDimmed (e: MouseEvent) {
if (closeClickDimmed && actionTarget === e.target) {
close.value()
}
actionTarget = null
}

function closeKeyEvent (event: KeyboardEvent) {
Expand All @@ -95,7 +103,8 @@ export const useClose: UseClose = ({ close, closeClickDimmed, closeKeyCode, late
})

return {
onClickDimmed
onMouseDownDimmed,
onMouseUpDimmed
}
}

Expand Down