Skip to content

Commit

Permalink
Merge pull request #1040 from szhsin/fix/onblur
Browse files Browse the repository at this point in the history
fix: onblur
  • Loading branch information
szhsin authored Aug 13, 2023
2 parents 0fa4274 + f547dca commit 63fb2ed
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dist/es/components/MenuContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const MenuContainer = ({
}
};
const onBlur = e => {
if (isOpen && !e.currentTarget.contains(e.relatedTarget || document.activeElement)) {
if (isOpen && !e.currentTarget.contains(e.relatedTarget)) {
safeCall(onClose, {
reason: CloseReason.BLUR
});
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ const MenuContainer = ({
}
};
const onBlur = e => {
if (isOpen && !e.currentTarget.contains(e.relatedTarget || document.activeElement)) {
if (isOpen && !e.currentTarget.contains(e.relatedTarget)) {
safeCall(onClose, {
reason: CloseReason.BLUR
});
Expand Down
18 changes: 9 additions & 9 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions example/src/components/Usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,8 @@ function ContextMenuExample() {
<Example
data={codeExamples.contextMenu}
onContextMenu={(e) => {
if (typeof document.hasFocus === 'function' && !document.hasFocus()) return;

e.preventDefault();
setAnchorPoint({ x: e.clientX, y: e.clientY });
setOpen(true);
Expand Down
2 changes: 2 additions & 0 deletions example/src/data/codeExamples.js
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,8 @@ export default function () {
return (
<div
onContextMenu={(e) => {
if (typeof document.hasFocus === 'function' && !document.hasFocus()) return;
e.preventDefault();
setAnchorPoint({ x: e.clientX, y: e.clientY });
setOpen(true);
Expand Down
4 changes: 2 additions & 2 deletions example/src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useEffect, useLayoutEffect } from 'react';
import { useTheme } from '../store';

export const version = '4.0.2';
export const build = '132';
export const version = '4.0.3';
export const build = '133';

export const bem = (block, element, modifiers = {}) => {
let blockElement = element ? `${block}__${element}` : block;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@szhsin/react-menu",
"version": "4.0.2",
"version": "4.0.3",
"description": "React component for building accessible menu, dropdown, submenu, context menu and more.",
"author": "Zheng Song",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/components/MenuContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const MenuContainer = ({
};

const onBlur = (e) => {
if (isOpen && !e.currentTarget.contains(e.relatedTarget || document.activeElement)) {
if (isOpen && !e.currentTarget.contains(e.relatedTarget)) {
safeCall(onClose, { reason: CloseReason.BLUR });
}
};
Expand Down

0 comments on commit 63fb2ed

Please sign in to comment.