mirror of
https://github.com/outline/outline.git
synced 2026-11-22 14:01:41 +03:00
fix: Header buttons not clickable while find panel is open (#13938)
* fix: Header buttons not clickable while find panel is open * Close find panel on repeated shortcut
This commit is contained in:
1 parent
50a7e61d83
commit
3b3da75c8b
1 file changed
+20
-10
@@ -34,6 +34,7 @@ type KeyboardShortcutsProps = {
|
||||
open: boolean;
|
||||
inputRef: React.RefObject<HTMLInputElement | null>;
|
||||
handleOpen: ({ withReplace }: { withReplace: boolean }) => void;
|
||||
handleClose: () => void;
|
||||
handleCaseSensitive: () => void;
|
||||
handleRegex: () => void;
|
||||
};
|
||||
@@ -42,18 +43,24 @@ function useKeyboardShortcuts({
|
||||
open,
|
||||
inputRef,
|
||||
handleOpen,
|
||||
handleClose,
|
||||
handleCaseSensitive,
|
||||
handleRegex,
|
||||
}: KeyboardShortcutsProps) {
|
||||
// Open popover
|
||||
// Toggle popover
|
||||
useKeyDown(
|
||||
(ev) =>
|
||||
isModKey(ev) &&
|
||||
ev.code === "KeyF" &&
|
||||
(!open || ev.altKey || document.activeElement !== inputRef.current) &&
|
||||
// Keyboard handler is through the AppMenu on Desktop v1.2.0+
|
||||
!(Desktop.bridge && "onFindInPage" in Desktop.bridge),
|
||||
(ev) => {
|
||||
// Close and fall through to the browser's find when already focused.
|
||||
if (open && !ev.altKey && document.activeElement === inputRef.current) {
|
||||
handleClose();
|
||||
return;
|
||||
}
|
||||
|
||||
ev.preventDefault();
|
||||
handleOpen({ withReplace: ev.altKey });
|
||||
},
|
||||
@@ -132,6 +139,10 @@ export default function FindAndReplace({
|
||||
}
|
||||
if ("onFindInPage" in Desktop.bridge) {
|
||||
Desktop.bridge.onFindInPage(() => {
|
||||
if (document.activeElement === inputRef.current) {
|
||||
setLocalOpen(false);
|
||||
return;
|
||||
}
|
||||
selectionRef.current = window.getSelection()?.toString();
|
||||
setLocalOpen(true);
|
||||
});
|
||||
@@ -186,6 +197,8 @@ export default function FindAndReplace({
|
||||
[localOpen, readOnly, selectInputText, selectInputReplaceText]
|
||||
);
|
||||
|
||||
const handleClose = React.useCallback(() => setLocalOpen(false), []);
|
||||
|
||||
const handleMore = React.useCallback(() => {
|
||||
setShowReplace((state) => !state);
|
||||
setTimeout(() => inputReplaceRef.current?.focus(), 100);
|
||||
@@ -341,6 +354,7 @@ export default function FindAndReplace({
|
||||
open: localOpen,
|
||||
inputRef,
|
||||
handleOpen,
|
||||
handleClose,
|
||||
handleCaseSensitive,
|
||||
handleRegex,
|
||||
});
|
||||
@@ -348,8 +362,8 @@ export default function FindAndReplace({
|
||||
const style: React.CSSProperties = React.useMemo(
|
||||
() => ({
|
||||
position: "fixed",
|
||||
top: 0,
|
||||
right: 0,
|
||||
top: 60,
|
||||
right: 16,
|
||||
zIndex: depths.popover,
|
||||
}),
|
||||
[]
|
||||
@@ -448,12 +462,11 @@ export default function FindAndReplace({
|
||||
width={0}
|
||||
minWidth={isMobile ? undefined : 420}
|
||||
scrollable={false}
|
||||
align="end"
|
||||
onEscapeKeyDown={handleEscape}
|
||||
onPointerDownOutside={(ev) => ev.preventDefault()}
|
||||
onFocusOutside={(ev) => ev.preventDefault()}
|
||||
style={{
|
||||
marginRight: 16,
|
||||
marginTop: 60,
|
||||
width: isMobile ? "calc(100vw - 32px)" : undefined,
|
||||
}}
|
||||
>
|
||||
@@ -503,10 +516,7 @@ export default function FindAndReplace({
|
||||
{isMobile && (
|
||||
<ControlsRow gap={4} align="center">
|
||||
{controls}
|
||||
<CloseButton
|
||||
onClick={() => setLocalOpen(false)}
|
||||
aria-label={t("Close")}
|
||||
>
|
||||
<CloseButton onClick={handleClose} aria-label={t("Close")}>
|
||||
<CloseIcon color={theme.textSecondary} />
|
||||
</CloseButton>
|
||||
</ControlsRow>
|
||||
|
||||
Reference in new issue
Block a user