< Summary

Information
Class: tui-search-bar.tsx
Assembly: app.components
File(s): /home/runner/work/ClutterStock/ClutterStock/frontend/app/components/tui-search-bar.tsx
Tag: 58_25416222083
Line coverage
0%
Covered lines: 0
Uncovered lines: 16
Coverable lines: 16
Total lines: 42
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/ClutterStock/ClutterStock/frontend/app/components/tui-search-bar.tsx

#LineLine coverage
 1import { useEffect, useRef } from "react";
 2
 03export function TuiSearchBar({ value, onChange, onClose }: {
 4  value: string;
 5  onChange: (v: string) => void;
 6  onClose: (clear: boolean) => void;
 7}) {
 08  const ref = useRef<HTMLInputElement>(null);
 9
 010  useEffect(() => {
 011    ref.current?.focus();
 012    ref.current?.select();
 13  }, []);
 14
 015  return (
 16    <div className="cs-search-bar">
 17      <span className="cs-search-prompt">/</span>
 18      <input
 19        ref={ref}
 20        type="text"
 21        value={value}
 022        onChange={(e) => onChange(e.target.value)}
 023        onKeyDown={(e) => {
 024          if (e.key === "Escape") {
 025            e.preventDefault();
 026            e.stopPropagation();
 027            onClose(true);
 028          } else if (e.key === "Enter") {
 029            e.preventDefault();
 030            e.stopPropagation();
 031            onClose(false);
 32          }
 33        }}
 34        placeholder="filter items… (Esc to clear, Enter to keep)"
 35        spellCheck={false}
 36        autoCorrect="off"
 37        autoCapitalize="off"
 38        className="cs-search-input"
 39      />
 40    </div>
 41  );
 42}