From 38842a3996f0ea25198a3b9c32069b3a089d4ee0 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Fri, 23 Jan 2026 14:16:08 +0100 Subject: [PATCH] Fix tooltip in AskAI flyout --- .../Assets/styles.css | 2 +- .../Assets/web-components/AskAi/Chat.tsx | 44 +++++++++++++------ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/Elastic.Documentation.Site/Assets/styles.css b/src/Elastic.Documentation.Site/Assets/styles.css index 839dedcc7..3951e43ab 100644 --- a/src/Elastic.Documentation.Site/Assets/styles.css +++ b/src/Elastic.Documentation.Site/Assets/styles.css @@ -72,7 +72,7 @@ body { } } -@media screen and (min-width: 1200px) { +@media screen and (min-width: 1180px) { :root { --offset-top: calc(80px + 38px); /* header height + banner height */ } diff --git a/src/Elastic.Documentation.Site/Assets/web-components/AskAi/Chat.tsx b/src/Elastic.Documentation.Site/Assets/web-components/AskAi/Chat.tsx index 7fc4704b8..b22232f54 100644 --- a/src/Elastic.Documentation.Site/Assets/web-components/AskAi/Chat.tsx +++ b/src/Elastic.Documentation.Site/Assets/web-components/AskAi/Chat.tsx @@ -121,6 +121,26 @@ const ChatHeader = () => { const messages = useChatMessages() const { euiTheme } = useEuiTheme() const smallFontsize = useEuiFontSize('s').fontSize + + // Prevent EUI's focus management from auto-focusing the clear button when it first appears. + // EUI components have internal focus management that tries to focus the first focusable + // element in a flyout when content changes. By temporarily setting tabIndex={-1}, we tell + // the focus management to skip this button during the initial render cycle. + const [isClearButtonFocusable, setIsClearButtonFocusable] = useState(false) + const prevHasMessages = useRef(messages.length > 0) + + useEffect(() => { + const hasMessages = messages.length > 0 + if (hasMessages && !prevHasMessages.current) { + // Button just appeared - delay focusability to avoid EUI's auto-focus + setIsClearButtonFocusable(false) + const timer = setTimeout(() => setIsClearButtonFocusable(true), 150) + prevHasMessages.current = hasMessages + return () => clearTimeout(timer) + } + prevHasMessages.current = hasMessages + }, [messages.length]) + return ( { gap: ${euiTheme.size.s}; `} > - - clearChat()} - css={css` - visibility: ${messages.length > 0 - ? 'visible' - : 'hidden'}; - `} - /> - + {messages.length > 0 && ( + + clearChat()} + tabIndex={isClearButtonFocusable ? 0 : -1} + /> + + )}