• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

teableio / teable / 10177782929

31 Jul 2024 09:35AM UTC coverage: 17.692% (-64.3%) from 81.98%
10177782929

push

github

web-flow
fix: `FieldSelctor` overflow could not scroll in some cases (#782)

1383 of 2808 branches covered (49.25%)

0 of 4 new or added lines in 2 files covered. (0.0%)

14026 of 79278 relevant lines covered (17.69%)

1.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/packages/sdk/src/components/search/SearchInput.tsx
1
import { Search, X } from '@teable/icons';
×
2
import { cn } from '@teable/ui-lib';
×
3
import { useCallback, useEffect, useRef, useState } from 'react';
×
4
import { useDebounce, useUnmount } from 'react-use';
×
5
import { useTranslation } from '../../context/app/i18n';
×
6
import { useFields } from '../../hooks/use-fields';
×
7
import { useSearch } from '../../hooks/use-search';
×
8
import { FieldSelector } from '../field/FieldSelector';
×
9

×
10
export function SearchInput({
×
11
  className,
×
12
  container,
×
13
}: {
×
14
  className?: string;
×
15
  container?: HTMLElement;
×
16
}) {
×
17
  const fields = useFields();
×
18
  const { fieldId, value, setFieldId, setValue, reset } = useSearch();
×
19
  const [inputValue, setInputValue] = useState(value);
×
20
  const [isFocused, setIsFocused] = useState(false);
×
21
  const { t } = useTranslation();
×
22

×
23
  const ref = useRef<HTMLInputElement>(null);
×
24

×
25
  const [, cancel] = useDebounce(
×
26
    () => {
×
27
      setValue(inputValue);
×
28
    },
×
29
    500,
×
30
    [inputValue]
×
31
  );
×
32

×
33
  const resetSearch = useCallback(() => {
×
34
    cancel();
×
35
    setValue();
×
36
    setInputValue('');
×
37
  }, [cancel, setValue]);
×
38

×
39
  useEffect(() => {
×
40
    if (!fieldId) {
×
41
      setFieldId(fields[0]?.id);
×
42
    }
×
43
  }, [fieldId, fields, setFieldId]);
×
44

×
45
  useUnmount(() => {
×
46
    cancel();
×
47
    reset();
×
48
  });
×
49

×
50
  return (
×
51
    <div
×
52
      className={cn(
×
53
        'left-6 top-60 flex grow h-8 shrink-0 items-center gap-1 overflow-hidden rounded-xl bg-background pr-2 text-sm border outline-muted-foreground',
×
54
        {
×
55
          outline: isFocused,
×
56
        },
×
57
        className
×
58
      )}
×
59
    >
×
60
      <FieldSelector
×
61
        className="h-full w-auto gap-1 rounded-none border-0 border-r px-1 text-sm font-normal"
×
62
        value={fieldId}
×
63
        container={container}
×
64
        onSelect={(value) => {
×
65
          setFieldId(value);
×
66
        }}
×
NEW
67
        modal
×
68
      />
×
69
      <input
×
70
        ref={ref}
×
71
        className="placeholder:text-muted-foregrounds grow rounded-md bg-transparent px-1 outline-none"
×
72
        placeholder={t('editor.link.searchPlaceholder')}
×
73
        autoComplete="off"
×
74
        autoCorrect="off"
×
75
        spellCheck="false"
×
76
        type="text"
×
77
        value={inputValue || ''}
×
78
        onChange={(e) => {
×
79
          setInputValue(e.target.value);
×
80
        }}
×
81
        onBlur={() => {
×
82
          setIsFocused(false);
×
83
        }}
×
84
        onFocus={() => {
×
85
          setIsFocused(true);
×
86
        }}
×
87
      />
×
88
      <X
×
89
        className={cn('hover:text-primary-foregrounds size-4 cursor-pointer font-light', {
×
90
          'opacity-20': !inputValue,
×
91
        })}
×
92
        onClick={() => {
×
93
          resetSearch();
×
94
        }}
×
95
      />
×
96
      <Search className="size-4" />
×
97
    </div>
×
98
  );
×
99
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc