Blur prop editors on unmount (#340)

This commit is contained in:
Andrew Prifer 2022-11-21 19:07:49 +01:00 committed by GitHub
parent a55a34d48f
commit 8c325c901a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View file

@ -1,5 +1,6 @@
import {clamp, isInteger, round} from 'lodash-es'
import type {MutableRefObject} from 'react'
import type {MutableRefObject} from 'react';
import { useEffect} from 'react'
import {useState} from 'react'
import React, {useMemo, useRef} from 'react'
import styled from 'styled-components'
@ -279,6 +280,13 @@ const BasicNumberInput: React.FC<{
}
}, [])
// Call onBlur on unmount. Because technically it _is_ a blur, but also, otherwise edits wouldn't be committed.
useEffect(() => {
return () => {
callbacks.onBlur()
}
}, [])
let value =
stateRef.current.mode !== 'editingViaKeyboard'
? format(propsA.value)

View file

@ -1,5 +1,6 @@
import styled from 'styled-components'
import type {MutableRefObject} from 'react'
import type {MutableRefObject} from 'react';
import { useEffect} from 'react'
import React, {useMemo, useRef} from 'react'
import mergeRefs from 'react-merge-refs'
import useRefAndState from '@theatre/studio/utils/useRefAndState'
@ -169,6 +170,13 @@ const BasicStringInput: React.FC<{
}
}, [])
// Call onBlur on unmount. Because technically it _is_ a blur, but also, otherwise edits wouldn't be committed.
useEffect(() => {
return () => {
callbacks.onBlur()
}
}, [])
let value =
stateRef.current.mode !== 'editingViaKeyboard'
? format(props.value)