mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-23 06:04:32 +01:00
auto focus
This commit is contained in:
4 files changed
+20
-1
No files matched your search
@@ -0,0 +1,10 @@
|
|||||||
|
<script is:inline>
|
||||||
|
// Focuses before hydration so the field is ready as soon as it's painted
|
||||||
|
for (const input of document.querySelectorAll("[data-auto-focus]")) {
|
||||||
|
const autoFocus = input.dataset.autoFocus;
|
||||||
|
|
||||||
|
if (window.matchMedia(`(pointer: ${autoFocus})`).matches) {
|
||||||
|
input.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -64,6 +64,7 @@ function Content({ topResult, onSelect }: SearchBarProps) {
|
|||||||
style={{ flex: 1 }}
|
style={{ flex: 1 }}
|
||||||
ref={input}
|
ref={input}
|
||||||
placeholder={strings.website.common.tank_search.search_bar_hint}
|
placeholder={strings.website.common.tank_search.search_bar_hint}
|
||||||
|
autoFocus="fine"
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -8,13 +8,15 @@ import {
|
|||||||
import { classNames } from "../../ui/classNames";
|
import { classNames } from "../../ui/classNames";
|
||||||
import styles from "./index.module.css";
|
import styles from "./index.module.css";
|
||||||
|
|
||||||
export interface TextFieldProps extends Omit<ComponentProps<"input">, "size"> {
|
export interface TextFieldProps
|
||||||
|
extends Omit<ComponentProps<"input">, "size" | "autoFocus"> {
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
align?: "left" | "center" | "right";
|
align?: "left" | "center" | "right";
|
||||||
autoWidth?: boolean;
|
autoWidth?: boolean;
|
||||||
variant?: "bubble" | "form";
|
variant?: "bubble" | "form";
|
||||||
size?: "regular" | "minor";
|
size?: "regular" | "minor";
|
||||||
childrenAsSuffix?: boolean;
|
childrenAsSuffix?: boolean;
|
||||||
|
autoFocus?: "coarse" | "fine" | "always";
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
|
export const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
|
||||||
@@ -30,6 +32,7 @@ export const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
|
|||||||
variant = "bubble",
|
variant = "bubble",
|
||||||
size = "regular",
|
size = "regular",
|
||||||
childrenAsSuffix,
|
childrenAsSuffix,
|
||||||
|
autoFocus,
|
||||||
...props
|
...props
|
||||||
},
|
},
|
||||||
ref,
|
ref,
|
||||||
@@ -52,6 +55,8 @@ export const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
|
|||||||
|
|
||||||
<input
|
<input
|
||||||
data-auto-width={autoWidth}
|
data-auto-width={autoWidth}
|
||||||
|
autoFocus={autoFocus === "always"}
|
||||||
|
data-auto-focus={autoFocus === "always" ? undefined : autoFocus}
|
||||||
data-align={align === "left" ? undefined : align}
|
data-align={align === "left" ? undefined : align}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
ref={input}
|
ref={input}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
---
|
---
|
||||||
|
import AutoFocus from "../components/AutoFocus.astro";
|
||||||
import BaseMeta from "../components/BaseMeta.astro";
|
import BaseMeta from "../components/BaseMeta.astro";
|
||||||
import BaseStyles from "../components/BaseStyles.astro";
|
import BaseStyles from "../components/BaseStyles.astro";
|
||||||
import ColorAlias from "../components/ColorAlias.astro";
|
import ColorAlias from "../components/ColorAlias.astro";
|
||||||
@@ -83,6 +84,8 @@ const { locale, accent, solidNavbar = false, tool } = Astro.props;
|
|||||||
<slot />
|
<slot />
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
|
<AutoFocus />
|
||||||
|
|
||||||
<NavbarFine {locale} {tool} />
|
<NavbarFine {locale} {tool} />
|
||||||
<NavbarCourse {locale} {tool} solid={solidNavbar} />
|
<NavbarCourse {locale} {tool} solid={solidNavbar} />
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in new issue
Block a user