mirror of
https://github.com/infinilabs/coco-app.git
synced 2025-12-23 23:09:25 +01:00
* chore: shadcn config * feat: add shadcn ui config * style: adjust styles * style: adjust styles * refactor: update style * style: adjust styles * style: adjust styles * style: adjust styles * style: adjust styles * refactor: update * refactor: update * refactor: update * refactor: update * style: adjust styles * style: adjust styles * refactor: update * refactor: update * refactor: update * refactor: update * refactor: update * refactor: update * style: web styles * refactor: update * style: web styles * style: web styles * refactor: update * refactor: update * refactor: update * chhore: add * chore: add * refactor: update * refactor: update * refactor: update * refactor: update * chore: update * refactor: update * refactor: update * refactor: update * refactor: update * refactor: update * refactor: update * chore: rename * refactor: update * refactor: update * chore: add * refactor: update * chore: update * chroe: up * refactor: update * refactor: update * chore: up * refactor: update * chore: up * feat: support for extracting css variables * chore: update * fix: fixed dark mode * refactor: update * refactor: update * refactor: update * refactor: update * docs: update release notes * style: adjust styles * style: adjust styles * refactor: update * refactor: update * refactor: update * refactor: update * refactor: update * refactor: update --------- Co-authored-by: ayang <473033518@qq.com>
37 lines
984 B
TypeScript
37 lines
984 B
TypeScript
import type { InputProps } from "@/components/ui/input";
|
|
import { Input } from "@/components/ui/input";
|
|
import { useKeyPress } from "ahooks";
|
|
import { forwardRef, useImperativeHandle, useRef } from "react";
|
|
|
|
import { POPOVER_PANEL_SELECTOR } from "@/constants";
|
|
|
|
const PopoverInput = forwardRef<HTMLInputElement, InputProps>((props, ref) => {
|
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
|
|
useImperativeHandle(ref, () => inputRef.current!);
|
|
|
|
useKeyPress(
|
|
"esc",
|
|
(event) => {
|
|
if (inputRef.current === document.activeElement) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
|
|
inputRef.current?.blur();
|
|
|
|
const parentPanel = inputRef.current?.closest(POPOVER_PANEL_SELECTOR);
|
|
if (parentPanel instanceof HTMLElement) {
|
|
parentPanel.focus();
|
|
}
|
|
}
|
|
},
|
|
{
|
|
target: inputRef,
|
|
}
|
|
);
|
|
|
|
return <Input autoCorrect="off" ref={inputRef} {...(props as any)} />;
|
|
});
|
|
|
|
export default PopoverInput;
|