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
select on first click, but position caret on a second
Oleg Isonen85c32eecd71b
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 910cbee30e..f25304b299 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@@ -130,6 +130,28 @@ const useUnitSelect = ({return [isUnitsOpen, element];};+const useSelect = (+ inputRef: React.MutableRefObject<HTMLInputElement | null>+) => {+ const shouldSelect = useRef(true);++ const onPointerUp = () => {+ if (shouldSelect.current) {+ inputRef.current?.select();+ }+ };++ const onPointerDown = () => {+ const isFocused = document.activeElement === inputRef.current;+ shouldSelect.current = isFocused === false;+ };++ return {+ onPointerUp,+ onPointerDown,+ };+};+const useScrub = (options: {value: StyleValue;onChange: (value: StyleValue) => void;@@ -137,14 +159,6 @@ const useScrub = (options: {}) => {const inputRef = useRef<HTMLInputElement | null>(null);const optionsRef = useRef(options);- const shouldSelect = useRef(true);-- const handlePointerUp = () => {- if (shouldSelect.current) {- inputRef.current?.select();- }- shouldSelect.current = true;- };useEffect(() => {optionsRef.current = options;@@ -157,7 +171,6 @@ const useScrub = (options: {const scrub = numericScrubControl(inputRef.current, {initialValue: value.value,onValueInput(event) {- shouldSelect.current = false;onChange({...value,value: event.value,@@ -176,10 +189,7 @@ const useScrub = (options: {};}, [options.value.type]);- return {- handlePointerUp,- inputRef,- };+ return inputRef;};const useKeyDown =@@ -290,12 +300,14 @@ export const CssValueInput = ({onChange: onChangeComplete,});- const { handlePointerUp, inputRef } = useScrub({+ const inputRef = useScrub({value,onChange,onChangeComplete,});+ const inputPointerProps = useSelect(inputRef);+const handleOnBlur: KeyboardEventHandler = (event) => {// When units select is open, onBlur is triggered,though we don't want a change event in this case.if (isUnitsOpen) return;@@ -326,7 +338,7 @@ export const CssValueInput = ({<ComboboxPopperAnchor><TextField{...inputProps}- onPointerUp={handlePointerUp}+ {...inputPointerProps}onBlur={handleOnBlur}onKeyDown={handleKeyDown}inputRef={inputRef}