Stop dark text fields from looking pre-selected when they auto-focus.
This commit is contained in:
1 parent
36112f95d3
commit
6aa06126b5
6 files changed
+111
-22
No files matched your search
@@ -21,6 +21,14 @@ import { useTranslation } from "../../../contexts/MessagesContext";
|
||||
import { SelectInputView } from "./SelectInput.view";
|
||||
import type { SelectInputProps, SelectOptionData } from "./SelectInput.types";
|
||||
|
||||
function isFocusVisible(el: Element): boolean {
|
||||
try {
|
||||
return el.matches(":focus-visible");
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Figma: "Control / SelectInput". Custom-styled select dropdown
|
||||
* with a labelled trigger button and floating option menu.
|
||||
@@ -277,11 +285,15 @@ const SelectInputContainer = forwardRef<HTMLButtonElement, SelectInputProps>(
|
||||
],
|
||||
);
|
||||
|
||||
// Handle focus to detect mouse vs keyboard
|
||||
const handleFocus = useCallback(() => {
|
||||
if (disabled) return;
|
||||
|
||||
const method = wasMouseDownRef.current ? "mouse" : "keyboard";
|
||||
const el = selectRef.current;
|
||||
const method = wasMouseDownRef.current
|
||||
? "mouse"
|
||||
: el && isFocusVisible(el)
|
||||
? "keyboard"
|
||||
: null;
|
||||
|
||||
if (shouldAutoManageFocus) {
|
||||
setIsFocused(true);
|
||||
@@ -308,15 +320,13 @@ const SelectInputContainer = forwardRef<HTMLButtonElement, SelectInputProps>(
|
||||
[closeMenu, shouldAutoManageFocus],
|
||||
);
|
||||
|
||||
// Determine actual state:
|
||||
// - Active: when clicked (mouse focus) or when dropdown is open
|
||||
// - Focus: when tabbed (keyboard focus)
|
||||
// - Default: when not focused
|
||||
const actualState = shouldAutoManageFocus
|
||||
? isOpen || isFocused
|
||||
? focusMethod === "mouse" || isOpen
|
||||
? "active"
|
||||
: "focus"
|
||||
: focusMethod === "keyboard"
|
||||
? "focus"
|
||||
: "default"
|
||||
: "default"
|
||||
: externalState;
|
||||
|
||||
|
||||
Reference in new issue
Block a user