Skip to content

Commit

Permalink
Blur prop editors on unmount (theatre-js#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewPrifer authored Nov 21, 2022
1 parent a55a34d commit 8c325c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion theatre/studio/src/uiComponents/form/BasicNumberInput.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion theatre/studio/src/uiComponents/form/BasicStringInput.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8c325c9

Please sign in to comment.