No more observer resize errors
This commit is contained in:
parent
6db749d21c
commit
11c1c2b9b4
@ -1,5 +1,6 @@
|
|||||||
import React, { useRef, useEffect, ChangeEvent, KeyboardEvent } from 'react';
|
import React, { useRef, useEffect, ChangeEvent, KeyboardEvent } from 'react';
|
||||||
import { useTheme } from '@mui/material/styles';
|
import { useTheme } from '@mui/material/styles';
|
||||||
|
import './BackstoryTextField.css';
|
||||||
|
|
||||||
interface BackstoryTextFieldProps {
|
interface BackstoryTextFieldProps {
|
||||||
value: string;
|
value: string;
|
||||||
@ -29,7 +30,7 @@ const BackstoryTextField: React.FC<BackstoryTextFieldProps> = ({
|
|||||||
|
|
||||||
shadow.value = value || placeholder || '';
|
shadow.value = value || placeholder || '';
|
||||||
|
|
||||||
window.setTimeout(() => {
|
window.requestAnimationFrame(() => {
|
||||||
const computed = getComputedStyle(textarea);
|
const computed = getComputedStyle(textarea);
|
||||||
const paddingTop = parseFloat(computed.paddingTop || '0');
|
const paddingTop = parseFloat(computed.paddingTop || '0');
|
||||||
const paddingBottom = parseFloat(computed.paddingBottom || '0');
|
const paddingBottom = parseFloat(computed.paddingBottom || '0');
|
||||||
@ -38,9 +39,9 @@ const BackstoryTextField: React.FC<BackstoryTextFieldProps> = ({
|
|||||||
const newHeight = shadow.scrollHeight + totalPadding;
|
const newHeight = shadow.scrollHeight + totalPadding;
|
||||||
|
|
||||||
textarea.style.height = `${newHeight}px`;
|
textarea.style.height = `${newHeight}px`;
|
||||||
}, 100);
|
});
|
||||||
}
|
}
|
||||||
}, [value, multiline, placeholder]);
|
}, [value, multiline, textareaRef, shadowRef, placeholder]);
|
||||||
|
|
||||||
const handleChange = (e: ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => {
|
const handleChange = (e: ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => {
|
||||||
if (onChange) {
|
if (onChange) {
|
||||||
@ -49,9 +50,6 @@ const BackstoryTextField: React.FC<BackstoryTextFieldProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement | HTMLInputElement>) => {
|
const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement | HTMLInputElement>) => {
|
||||||
if (!multiline && e.key === 'Enter') {
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
if (onKeyDown) {
|
if (onKeyDown) {
|
||||||
onKeyDown(e);
|
onKeyDown(e);
|
||||||
}
|
}
|
||||||
@ -59,15 +57,14 @@ const BackstoryTextField: React.FC<BackstoryTextFieldProps> = ({
|
|||||||
|
|
||||||
const sharedStyle = {
|
const sharedStyle = {
|
||||||
width: '100%',
|
width: '100%',
|
||||||
padding: '14px',
|
padding: '16.5px 14px',
|
||||||
resize: 'none' as const,
|
resize: 'none' as const,
|
||||||
overflow: 'hidden' as const,
|
overflow: 'hidden' as const,
|
||||||
boxSizing: 'border-box' as const,
|
boxSizing: 'border-box' as const,
|
||||||
|
minHeight: 'calc(1.5rem + 28px)', // lineHeight + padding-top + padding-bottom
|
||||||
lineHeight: '1.5',
|
lineHeight: '1.5',
|
||||||
borderRadius: '0.25rem',
|
borderRadius: '4px',
|
||||||
fontSize: '16px',
|
fontSize: '16px',
|
||||||
opacity: disabled ? "0.38" : "1",
|
|
||||||
color: disabled ? 'rgba(0, 0, 0, 0.38)' : 'rgb(46, 46, 46)',
|
|
||||||
backgroundColor: 'rgba(0, 0, 0, 0)',
|
backgroundColor: 'rgba(0, 0, 0, 0)',
|
||||||
fontFamily: theme.typography.fontFamily,
|
fontFamily: theme.typography.fontFamily,
|
||||||
};
|
};
|
||||||
@ -75,6 +72,7 @@ const BackstoryTextField: React.FC<BackstoryTextFieldProps> = ({
|
|||||||
if (!multiline) {
|
if (!multiline) {
|
||||||
return (
|
return (
|
||||||
<input
|
<input
|
||||||
|
className="BackstoryTextField"
|
||||||
type="text"
|
type="text"
|
||||||
value={value}
|
value={value}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
@ -89,6 +87,7 @@ const BackstoryTextField: React.FC<BackstoryTextFieldProps> = ({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<textarea
|
<textarea
|
||||||
|
className="BackstoryTextField"
|
||||||
ref={textareaRef}
|
ref={textareaRef}
|
||||||
value={value}
|
value={value}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
@ -101,8 +100,10 @@ const BackstoryTextField: React.FC<BackstoryTextFieldProps> = ({
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<textarea
|
<textarea
|
||||||
|
className="BackgroundTextField"
|
||||||
ref={shadowRef}
|
ref={shadowRef}
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
|
value={placeholder || ""}
|
||||||
style={{
|
style={{
|
||||||
...sharedStyle,
|
...sharedStyle,
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
@ -113,6 +114,7 @@ const BackstoryTextField: React.FC<BackstoryTextFieldProps> = ({
|
|||||||
margin: '0px',
|
margin: '0px',
|
||||||
overflow: 'auto',
|
overflow: 'auto',
|
||||||
height: '0px',
|
height: '0px',
|
||||||
|
minHeight: '0px',
|
||||||
}}
|
}}
|
||||||
readOnly
|
readOnly
|
||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
|
@ -146,14 +146,6 @@ const VectorVisualizer: React.FC<VectorVisualizerProps> = (props: VectorVisualiz
|
|||||||
|
|
||||||
fetchCollection();
|
fetchCollection();
|
||||||
}, [result, setResult, connectionBase, setSnack, sessionId, view2D])
|
}, [result, setResult, connectionBase, setSnack, sessionId, view2D])
|
||||||
|
|
||||||
/* Trigger a resize event to force Plotly to rescale */
|
|
||||||
useEffect(() => {
|
|
||||||
window.dispatchEvent(new Event('resize'));
|
|
||||||
if (plotlyRef.current) {
|
|
||||||
Plot.Plots.resize(plotlyRef.current);
|
|
||||||
}
|
|
||||||
}, [plotlyRef])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!result || !result.embeddings) return;
|
if (!result || !result.embeddings) return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user