Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
Fix performance issue with scrub when used inside popover (#633)
Roman Pominovdcd7d8c43a87
diff --git a/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx b/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsxindex a6bf5b9ef2..283a06f7f7 100644--- a/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx+++ b/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx@@ -26,7 +26,6 @@ import {useCallback,useEffect,useRef,- useState,} from "react";import { useIsFromCurrentBreakpoint } from "../use-is-from-current-breakpoint";import { useUnitSelect } from "./unit-select";@@ -58,12 +57,10 @@ const useScrub = ({shouldHandleEvent?: (node: EventTarget) => boolean;}): [React.MutableRefObject<HTMLDivElement | null>,- React.MutableRefObject<HTMLInputElement | null>,- boolean+ React.MutableRefObject<HTMLInputElement | null>] => {const scrubRef = useRef<HTMLDivElement | null>(null);const inputRef = useRef<HTMLInputElement | null>(null);- const [isInputActive, setIsInputActive] = useState(false);const onChangeRef = useRef(onChange);const onChangeCompleteRef = useRef(onChangeComplete);@@ -107,8 +104,9 @@ const useScrub = ({}},onValueInput(event) {- setIsInputActive(true);- inputRefCurrent.blur();+ // Moving focus to container of the input to hide the caret+ // (it makes text harder to read and may jump around as you scrub)+ scrubRef.current?.focus();onChangeRef.current({type,@@ -127,9 +125,9 @@ const useScrub = ({});});- setIsInputActive(false);- inputRefCurrent.focus();- inputRefCurrent.select();+ // Returning focus that we've moved above+ inputRef.current?.focus();+ inputRef.current?.select();},shouldHandleEvent: shouldHandleEvent,});@@ -137,7 +135,7 @@ const useScrub = ({return scrub.disconnectedCallback;}, [type, unit, shouldHandleEvent]);- return [scrubRef, inputRef, isInputActive];+ return [scrubRef, inputRef];};const useHandleKeyDown =@@ -308,7 +306,8 @@ export const CssValueInput = ({const shouldHandleEvent = useCallback((node) => {return suffixRef.current?.contains?.(node) === false;}, []);- const [scrubRef, inputRef, isInputActive] = useScrub({++ const [scrubRef, inputRef] = useScrub({value,onChange: props.onChange,onChangeComplete,@@ -392,13 +391,7 @@ export const CssValueInput = ({baseRef={scrubRef}inputRef={inputRef}name={property}- state={- value.type === "invalid"- ? "invalid"- : isInputActive- ? "active"- : undefined- }+ state={value.type === "invalid" ? "invalid" : undefined}prefix={prefix}suffix={suffix}css={{ cursor: "default" }}diff --git a/packages/design-system/src/components/primitives/numeric-gesture-control.ts b/packages/design-system/src/components/primitives/numeric-gesture-control.tsindex 03c1a61c3c..b2fe43fc41 100644--- a/packages/design-system/src/components/primitives/numeric-gesture-control.ts+++ b/packages/design-system/src/components/primitives/numeric-gesture-control.ts@@ -37,7 +37,6 @@ export type NumericScrubOptions = {type NumericScrubState = {value: number;cursor?: SVGElement;- velocity: number;direction: string;timerId?: ReturnType<typeof window.setTimeout>;};@@ -59,7 +58,6 @@ export const numericScrubControl = (// We will read value lazyly in a moment it will be used to avoid having outdated valuevalue: -1,cursor: undefined,- velocity: direction === "horizontal" ? 1 : -1,direction: direction,timerId: undefined,};diff --git a/packages/design-system/src/components/text-field.tsx b/packages/design-system/src/components/text-field.tsxindex ebff406e6a..49afde21ba 100644--- a/packages/design-system/src/components/text-field.tsx+++ b/packages/design-system/src/components/text-field.tsx@@ -314,6 +314,11 @@ export const TextField = React.forwardRef<HTMLDivElement, TextFieldProps>(withPrefix={Boolean(prefix)}withSuffix={Boolean(suffix)}onClickCapture={focusInnerInput}+ // Setting tabIndex to -1 to allow this element to be focused via JavaScript.+ // This is used when we need to hide the caret but want to:+ // 1. keep the visual focused state of the component+ // 2. keep focus somewhere insisde the component to not trigger some focus-trap logic+ tabIndex={-1}>{/* We want input to be the first element in DOM so it receives the focus first */}<InputBase