Skip to content

Commit 96538b6

Browse files
committed
add comment about react >= 17 focus event listeners
1 parent 7557adc commit 96538b6

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

packages/slate-react/src/components/slate.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ export const Slate = (props: {
7272
useIsomorphicLayoutEffect(() => {
7373
const fn = () => setIsFocused(ReactEditor.isFocused(editor))
7474
if (IS_REACT_VERSION_17_OR_ABOVE) {
75+
// In React >= 17 onFocus and onBlur listen to the focusin and focusout events during the bubbling phase.
76+
// Therefore in order for <Editable />'s handlers to run first, which is necessary for ReactEditor.isFocused(editor)
77+
// to return the correct value, we have to listen to the focusin and focusout events without useCapture here.
7578
document.addEventListener('focusin', fn)
7679
document.addEventListener('focusout', fn)
7780
return () => {

0 commit comments

Comments
 (0)