Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed issue inserting functions in LG #6388

Merged
merged 2 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const StringArrayEditor = React.memo(
const containerRef = useRef<HTMLDivElement | null>(null);

const [currentIndex, setCurrentIndex] = useState<number | null>(items.length === 1 && items[0] === '' ? 0 : null);
const [calloutTargetElement, setCalloutTargetElement] = useState<HTMLInputElement | null>(null);
const [calloutTargetElement, setCalloutTargetElement] = useState<HTMLTextAreaElement | null>(null);

const onItemChange = useCallback(
(index: number) => (_, newValue?: string) => {
Expand Down Expand Up @@ -112,7 +112,7 @@ export const StringArrayEditor = React.memo(
setCurrentIndex(items.length);
}, [items, onChange]);

const onShowCallout = useCallback((targetElement: HTMLInputElement) => {
const onShowCallout = useCallback((targetElement: HTMLTextAreaElement) => {
setCalloutTargetElement(targetElement);
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const Input = styled(TextField)({
position: 'relative',
'& input, & textarea': {
fontSize: FluentTheme.fonts.small.fontSize,
maxHeight: '97px',
},
'& .ms-TextField-fieldGroup::after': {
content: '""',
Expand Down Expand Up @@ -89,8 +90,6 @@ const textFieldStyles = {
},
};

const textFieldResizeMaxCharsThreshold = 25;

type Props = {
mode: 'edit' | 'view';
editorMode?: 'single' | 'editor';
Expand All @@ -105,9 +104,9 @@ type Props = {
onJumpTo?: (direction: 'next' | 'previous') => void;
onRemove: () => void;
onFocus: () => void;
onChange?: (event: React.FormEvent<HTMLInputElement | HTMLTextAreaElement>, value?: string) => void;
onChange?: (event: React.FormEvent<HTMLTextAreaElement | HTMLInputElement>, value?: string) => void;
onLgChange?: (value: string) => void;
onShowCallout?: (target: HTMLInputElement) => void;
onShowCallout?: (target: HTMLTextAreaElement) => void;
};

type TextViewItemProps = Pick<Props, 'value' | 'onRemove' | 'onFocus' | 'onRenderDisplayText' | 'codeEditorSettings'>;
Expand Down Expand Up @@ -157,34 +156,35 @@ type TextFieldItemProps = Omit<Props, 'onRemove' | 'mode' | 'onFocus' | 'telemet
const TextFieldItem = React.memo(({ value, onShowCallout, onChange }: TextFieldItemProps) => {
const itemRef = useRef<ITextField | null>(null);
const containerRef = useRef<HTMLDivElement | null>(null);
const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement | null>(null);
const inputRef = useRef<HTMLTextAreaElement | null>(null);

useEffect(() => {
itemRef.current?.focus();
if (containerRef.current) {
inputRef.current = containerRef.current.querySelector('input');
inputRef.current = containerRef.current.querySelector('textarea');
}
}, []);

const focus = React.useCallback(
(e: React.FocusEvent<HTMLInputElement>) => {
(e: React.FocusEvent<HTMLTextAreaElement>) => {
e.stopPropagation();
onShowCallout?.(e.target as HTMLInputElement);
onShowCallout?.(e.target as HTMLTextAreaElement);
},
[onShowCallout]
);

const click = React.useCallback(
(e: React.MouseEvent<HTMLInputElement>) => {
(e: React.MouseEvent<HTMLTextAreaElement>) => {
e.stopPropagation();
onShowCallout?.(e.target as HTMLInputElement);
onShowCallout?.(e.target as HTMLTextAreaElement);
},
[onShowCallout]
);

React.useEffect(() => {
if (inputRef.current && inputRef.current.value !== value) {
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value')?.set;
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, 'value')
?.set;
if (nativeInputValueSetter) {
nativeInputValueSetter.call(inputRef.current, value);
const inputEvent = new Event('input', { bubbles: true });
Expand All @@ -196,9 +196,10 @@ const TextFieldItem = React.memo(({ value, onShowCallout, onChange }: TextFieldI
return (
<div ref={containerRef}>
<Input
autoAdjustHeight
multiline
componentRef={(ref) => (itemRef.current = ref)}
defaultValue={value}
multiline={value.length > textFieldResizeMaxCharsThreshold}
resizable={false}
styles={textFieldStyles}
onChange={onChange}
Expand Down