Skip to content

Commit

Permalink
fix(form-builder): remove empty value on array item dialog close
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Apr 13, 2021
1 parent 9891a95 commit 714b1f3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const SCROLL_OPTIONS = {scrollMode: 'if-needed'} as const
* @param hasFocusWithin A boolean indicating whether we have has focus within the currently edited value
*/
export function useScrollIntoViewOnFocusWithin(
elementRef: {current?: HTMLElement | null},
elementRef: {current: HTMLElement | null},
hasFocusWithin: boolean
): void {
return useDidUpdate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {ArrayMember} from '../types'
import {EMPTY_ARRAY} from '../../../../utils/empty'
import {hasFocusWithinPath} from '../../../../utils/focusUtils'
import {useScrollIntoViewOnFocusWithin} from '../../../../hooks/useScrollIntoViewOnFocusWithin'
import {getItemType} from './helpers'
import {getItemType, isEmpty} from './helpers'
import {EditDialog} from './EditDialog'
import {ItemRow} from './ItemRow'
import {ItemCell} from './ItemCell'
Expand Down Expand Up @@ -66,7 +66,12 @@ export function ArrayItem(props: ArrayInputListItemProps) {

const handleFocus = useCallback(() => emitFocus(), [emitFocus])
const handleEditOpen = useCallback(() => emitFocus([FOCUS_TERMINATOR]), [emitFocus])
const handleEditClose = useCallback(() => emitFocus(), [emitFocus])
const handleEditClose = useCallback(() => {
if (isEmpty(value)) {
onRemove(value)
}
emitFocus()
}, [value, onRemove, emitFocus])

const handleChange = useCallback(
(event: PatchEvent, valueOverride?: ArrayMember) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {resolveTypeName} from '../../../../utils/resolveTypeName'
import {IGNORE_KEYS} from './constants'

// eslint-disable-next-line @typescript-eslint/ban-types
export function isEmpty(value: any): value is Record<never, never> {
export function isEmpty(value: Record<string, unknown>): value is Record<never, never> {
return Object.keys(value).every((key) => IGNORE_KEYS.includes(key))
}

Expand Down

2 comments on commit 714b1f3

@vercel
Copy link

@vercel vercel bot commented on 714b1f3 Apr 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

perf-studio – ./

perf-studio-git-next.sanity.build
perf-studio.sanity.build

@vercel
Copy link

@vercel vercel bot commented on 714b1f3 Apr 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

test-studio – ./

test-studio-git-next.sanity.build
test-studio.sanity.build

Please sign in to comment.