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

teableio / teable / 8453146631

27 Mar 2024 02:08PM CUT coverage: 21.838% (+0.001%) from 21.837%
8453146631

push

github

web-flow
fix: date field grouping collapse (#505)

* fix: date field grouping collapse

* fix: remove redundant record menu items

* fix: long text field editor style

1396 of 2499 branches covered (55.86%)

0 of 10 new or added lines in 3 files covered. (0.0%)

14539 of 66576 relevant lines covered (21.84%)

2.09 hits per line

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

0.0
/packages/sdk/src/components/grid/components/editor/TextEditor.tsx
1
import { Input } from '@teable/ui-lib';
×
2
import type { ChangeEvent, ForwardRefRenderFunction, KeyboardEvent, RefObject } from 'react';
×
3
import { useState, useRef, useImperativeHandle, forwardRef, useMemo } from 'react';
×
4
import AutoSizeTextarea from 'react-textarea-autosize';
×
5
import { Key } from 'ts-keycode-enum';
×
6
import { GRID_DEFAULT } from '../../configs';
×
7
import type { ILinkCell, INumberCell, ITextCell } from '../../renderers';
×
8
import { CellType } from '../../renderers';
×
9
import type { IEditorRef, IEditorProps } from './EditorContainer';
×
10

×
11
const { rowHeight: defaultRowHeight } = GRID_DEFAULT;
×
12

×
13
const TextEditorBase: ForwardRefRenderFunction<
×
14
  IEditorRef<ITextCell | INumberCell>,
×
15
  IEditorProps<ITextCell | INumberCell | ILinkCell>
×
16
> = (props, ref) => {
×
17
  const { cell, rect, style, theme, isEditing, onChange } = props;
×
18
  const { cellLineColorActived } = theme;
×
19
  const { width, height } = rect;
×
20
  const { displayData, type } = cell;
×
21
  const needWrap = (cell as ITextCell)?.isWrap;
×
22
  const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement>(null);
×
23
  const [value, setValueInner] = useState(displayData);
×
24

×
25
  useImperativeHandle(ref, () => ({
×
26
    focus: () => inputRef.current?.focus(),
×
27
    setValue: (value: string | number | null | undefined) => setValueInner(String(value ?? '')),
×
28
    saveValue,
×
29
  }));
×
30

×
31
  const saveValue = () => {
×
32
    if (value === displayData || !isEditing) return;
×
33
    onChange?.(type === CellType.Number ? Number(value) : value);
×
34
  };
×
35

×
36
  const onChangeInner = (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
×
37
    const value = e.target.value;
×
38
    setValueInner(value);
×
39
  };
×
40

×
41
  const onKeyDown = (event: KeyboardEvent<HTMLTextAreaElement>) => {
×
42
    const { keyCode, shiftKey } = event;
×
43
    if (keyCode === Key.Enter && !shiftKey) {
×
44
      event.preventDefault();
×
45
    }
×
46
    if (keyCode === Key.Enter && shiftKey) {
×
47
      event.stopPropagation();
×
48
    }
×
49
  };
×
50

×
51
  const attachStyle = useMemo(() => {
×
52
    const style: React.CSSProperties = {
×
53
      width: width + 4,
×
NEW
54
      minHeight: height + 4,
×
55
      height: needWrap ? 'auto' : height + 4,
×
56
      marginLeft: -2,
×
NEW
57
      marginTop: -2,
×
58
      textAlign: type === CellType.Number ? 'right' : 'left',
×
59
    };
×
60
    if (height > defaultRowHeight) {
×
61
      style.paddingBottom = height - defaultRowHeight;
×
62
    }
×
63
    return style;
×
64
  }, [type, height, width, needWrap]);
×
65

×
66
  return (
×
67
    <>
×
68
      {needWrap ? (
×
69
        <div
×
70
          style={{
×
71
            ...style,
×
72
            ...attachStyle,
×
73
            paddingBottom: 16,
×
74
            border: `2px solid ${cellLineColorActived}`,
×
75
          }}
×
76
          className="relative rounded-md bg-background"
×
77
        >
×
78
          <AutoSizeTextarea
×
79
            ref={inputRef as RefObject<HTMLTextAreaElement>}
×
80
            className="w-full resize-none rounded border-none bg-background px-2 pt-2 text-sm leading-6 focus-visible:outline-none"
×
81
            value={value}
×
82
            minRows={2}
×
83
            maxRows={5}
×
84
            onBlur={saveValue}
×
85
            onKeyDown={onKeyDown}
×
86
            onChange={onChangeInner}
×
87
          />
×
88
          <div className="absolute bottom-[2px] left-0 w-full rounded-b-md bg-background pb-[2px] pr-1 text-right text-xs text-slate-400 dark:text-slate-600">
×
89
            Shift + Enter
×
90
          </div>
×
91
        </div>
×
92
      ) : (
×
93
        <Input
×
94
          ref={inputRef as RefObject<HTMLInputElement>}
×
95
          style={{
×
96
            border: `2px solid ${cellLineColorActived}`,
×
97
            ...style,
×
98
            ...attachStyle,
×
99
          }}
×
100
          value={value}
×
101
          className="cursor-text border-2 px-2 shadow-none focus-visible:ring-transparent"
×
102
          onChange={onChangeInner}
×
103
          onBlur={saveValue}
×
104
          onMouseDown={(e) => e.stopPropagation()}
×
105
        />
×
106
      )}
×
107
    </>
×
108
  );
×
109
};
×
110

×
111
export const TextEditor = forwardRef(TextEditorBase);
×
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