From a92471549e066c23e9345055051847717028ada6 Mon Sep 17 00:00:00 2001 From: Malik Glossop Date: Tue, 27 Jan 2026 14:25:16 +0100 Subject: [PATCH] Merge pull request #30956 from overleaf/mg-fix-dark-mode-spellcheck-style Fix dark mode spellcheck style GitOrigin-RevId: 1b4560637a98d3c7bcd2a2aa637f7f1fe19b469c --- .../spelling/spelling-suggestions.tsx | 75 ++++++++++--------- .../stylesheets/components/dropdown-menu.scss | 3 +- 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/services/web/frontend/js/features/source-editor/extensions/spelling/spelling-suggestions.tsx b/services/web/frontend/js/features/source-editor/extensions/spelling/spelling-suggestions.tsx index 724f79c652..eaba8b768f 100644 --- a/services/web/frontend/js/features/source-editor/extensions/spelling/spelling-suggestions.tsx +++ b/services/web/frontend/js/features/source-editor/extensions/spelling/spelling-suggestions.tsx @@ -1,9 +1,9 @@ import { FC, MouseEventHandler, - useCallback, useEffect, useMemo, + useRef, useState, } from 'react' import { SpellChecker, Word } from './spellchecker' @@ -15,7 +15,13 @@ import { SpellingSuggestionsLanguage } from './spelling-suggestions-language' import { captureException } from '@/infrastructure/error-reporter' import { debugConsole } from '@/utils/debugging' import { SpellCheckLanguage } from '../../../../../../types/project-settings' -import { Dropdown } from 'react-bootstrap' +import { + Dropdown, + DropdownDivider, + DropdownItem, + DropdownMenu, +} from '@/shared/components/dropdown/dropdown-menu' +import DropdownListItem from '@/shared/components/dropdown/dropdown-list-item' const ITEMS_TO_SHOW = 8 @@ -102,15 +108,30 @@ const B5SpellingSuggestions: FC = ({ handleLearnWord, }) => { const { t } = useTranslation() + const menuRef = useRef(null) + + // Handle closing the menu when it loses focus, e.g. click outside the editor + const onToggle = (show: boolean) => { + if (!show) { + handleClose() + } + } + + useEffect(() => { + if (!waiting) { + menuRef.current?.focus() + } + }, [waiting]) + return ( - - + { switch (event.code) { case 'Escape': @@ -122,58 +143,40 @@ const B5SpellingSuggestions: FC = ({ }} > {Array.isArray(suggestions) && - suggestions.map((suggestion, index) => ( - ( + { event.preventDefault() handleCorrectWord(suggestion) }} - // eslint-disable-next-line jsx-a11y/no-autofocus - autoFocus={index === 0} /> ))} - {suggestions?.length > 0 && } - 0 && } + { event.preventDefault() handleLearnWord() }} - // eslint-disable-next-line jsx-a11y/no-autofocus - autoFocus={suggestions?.length === 0} /> - + - + ) } -const BS5ListItem: FC<{ +const SpellingListItem: FC<{ content: string handleClick: MouseEventHandler - autoFocus?: boolean -}> = ({ content, handleClick, autoFocus }) => { - const handleListItem = useCallback( - (node: HTMLElement | null) => { - if (node && autoFocus) node.focus() - }, - [autoFocus] - ) - return ( - - {content} - - ) -} +}> = ({ content, handleClick }) => ( + + {content} + +) diff --git a/services/web/frontend/stylesheets/components/dropdown-menu.scss b/services/web/frontend/stylesheets/components/dropdown-menu.scss index 64ed25e585..507d603ad8 100644 --- a/services/web/frontend/stylesheets/components/dropdown-menu.scss +++ b/services/web/frontend/stylesheets/components/dropdown-menu.scss @@ -40,7 +40,8 @@ .ide-redesign-main, .project-ds-nav-page, // Codemirror tooltips are rendered outside of the main app container - .cm-tooltip .dropdown-menu { + .cm-tooltip .dropdown-menu, + .cm-tooltip .dropdown { @include dark-dropdown-menu; } }