Skip to content

Commit cdb5513

Browse files
committed
refactor: clean up useEffect in InlineUI and enhance prop documentation in Marker Edit component
1 parent 0b09a67 commit cdb5513

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

src/infotip/edit.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,18 @@ export function Edit({ value, onChange, onFocus, isActive, contentRef, activeAtt
2929
const [isSettingOpen, setIsSettingOpen] = useState(false);
3030

3131
useEffect(() => {
32-
if (!isActive) {
33-
setIsSettingOpen(false);
34-
}
35-
}, [isActive]);
32+
return () => {
33+
const { ownerDocument } = contentRef.current;
34+
const infotips = ownerDocument.querySelectorAll(
35+
'tatva-infotip'
36+
);
37+
infotips.forEach((infotip) => {
38+
if (infotip && typeof infotip.hideTooltip === 'function') {
39+
infotip.hideTooltip();
40+
}
41+
});
42+
};
43+
}, [contentRef]);
3644

3745
return (
3846
<>

src/infotip/inline-ui.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44
import { __ } from '@wordpress/i18n';
55
import { useAnchor } from '@wordpress/rich-text';
6-
import { useEffect } from '@wordpress/element';
76
import { Popover, TabPanel } from '@wordpress/components';
87

98
/**
@@ -42,20 +41,6 @@ function InlineUI({
4241
settings: { isActive },
4342
});
4443

45-
useEffect(() => {
46-
return () => {
47-
const { ownerDocument } = contentRef;
48-
const infotips = ownerDocument.querySelectorAll(
49-
'tatva-infotip'
50-
);
51-
infotips.forEach((infotip) => {
52-
if (infotip && typeof infotip.hideTooltip === 'function') {
53-
infotip.hideTooltip();
54-
}
55-
});
56-
};
57-
}, [contentRef]);
58-
5944
return (
6045
<Popover
6146
anchor={anchor}

src/marker/edit.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ import InlineUI from './inline-ui';
1515
* Edit component for the Marker format in the block editor.
1616
*
1717
* @param {Object} props - The component properties.
18-
* @return {JSX.Element} The rendered component.
18+
* @param {Object} props.value - The current value of the rich text.
19+
* @param {Function} props.onChange - Function to update the rich text value.
20+
* @param {boolean} props.isActive - Indicates if the format is currently active.
21+
* @param {Object} props.contentRef - Reference to the editable content element.
22+
* @param {Object} props.activeAttributes - The currently active attributes.
23+
* @return {JSX.Element} - The rendered Marker formats.
1924
*/
20-
export function Edit(props) {
21-
const { value, onChange, isActive, contentRef, activeAttributes } = props;
25+
export function Edit({ value, onChange, isActive, contentRef, activeAttributes }) {
2226
const [isSettingOpen, setIsSettingOpen] = useState(false);
2327

2428
return (

0 commit comments

Comments
 (0)