Fix InputGroup not refreshing when selecting a different element

This commit is contained in:
Eric NGUYEN 2022-09-13 18:12:20 +02:00
parent 021af3e70f
commit 7494383f58
2 changed files with 14 additions and 1 deletions

View file

@ -62,6 +62,7 @@ export function ContainerForm(props: IContainerFormProps): JSX.Element {
value={props.properties.type} value={props.properties.type}
isDisabled={true} /> isDisabled={true} />
<TextInputGroup <TextInputGroup
key={`${props.properties.id}-displayedText`}
labelText='Displayed text' labelText='Displayed text'
inputKey='displayedText' inputKey='displayedText'
labelClassName='' labelClassName=''
@ -70,6 +71,7 @@ export function ContainerForm(props: IContainerFormProps): JSX.Element {
value={props.properties.displayedText?.toString()} value={props.properties.displayedText?.toString()}
onChange={(value) => props.onChange('displayedText', value)} /> onChange={(value) => props.onChange('displayedText', value)} />
<TextInputGroup <TextInputGroup
key={`${props.properties.id}-x`}
labelText='x' labelText='x'
inputKey='x' inputKey='x'
labelClassName='' labelClassName=''
@ -89,6 +91,7 @@ export function ContainerForm(props: IContainerFormProps): JSX.Element {
) )
)} /> )} />
<TextInputGroup <TextInputGroup
key={`${props.properties.id}-y`}
labelText='y' labelText='y'
inputKey='y' inputKey='y'
labelClassName='' labelClassName=''
@ -97,6 +100,7 @@ export function ContainerForm(props: IContainerFormProps): JSX.Element {
value={(props.properties.y - (props.properties.margin?.top ?? 0)).toString()} value={(props.properties.y - (props.properties.margin?.top ?? 0)).toString()}
onChange={(value) => props.onChange('y', Number(value) + (props.properties.margin?.top ?? 0))} /> onChange={(value) => props.onChange('y', Number(value) + (props.properties.margin?.top ?? 0))} />
<TextInputGroup <TextInputGroup
key={`${props.properties.id}-minWidth`}
labelText='Minimum width' labelText='Minimum width'
inputKey='minWidth' inputKey='minWidth'
labelClassName='' labelClassName=''
@ -106,6 +110,7 @@ export function ContainerForm(props: IContainerFormProps): JSX.Element {
value={props.properties.minWidth.toString()} value={props.properties.minWidth.toString()}
onChange={(value) => props.onChange('minWidth', Number(value))} /> onChange={(value) => props.onChange('minWidth', Number(value))} />
<TextInputGroup <TextInputGroup
key={`${props.properties.id}-maxWidth`}
labelText='Maximum width' labelText='Maximum width'
inputKey='maxWidth' inputKey='maxWidth'
labelClassName='' labelClassName=''
@ -115,6 +120,7 @@ export function ContainerForm(props: IContainerFormProps): JSX.Element {
value={props.properties.maxWidth.toString()} value={props.properties.maxWidth.toString()}
onChange={(value) => props.onChange('maxWidth', Number(value))} /> onChange={(value) => props.onChange('maxWidth', Number(value))} />
<TextInputGroup <TextInputGroup
key={`${props.properties.id}-width`}
labelText='Width' labelText='Width'
inputKey='width' inputKey='width'
labelClassName='' labelClassName=''
@ -126,6 +132,7 @@ export function ContainerForm(props: IContainerFormProps): JSX.Element {
onChange={(value) => props.onChange('width', ApplyWidthMargin(Number(value), props.properties.margin.left, props.properties.margin.right))} onChange={(value) => props.onChange('width', ApplyWidthMargin(Number(value), props.properties.margin.left, props.properties.margin.right))}
isDisabled={props.properties.isFlex} /> isDisabled={props.properties.isFlex} />
<TextInputGroup <TextInputGroup
key={`${props.properties.id}-height`}
labelText='Height' labelText='Height'
inputKey='height' inputKey='height'
labelClassName='' labelClassName=''
@ -135,6 +142,7 @@ export function ContainerForm(props: IContainerFormProps): JSX.Element {
value={(props.properties.height + (props.properties.margin?.top ?? 0) + (props.properties.margin?.bottom ?? 0)).toString()} value={(props.properties.height + (props.properties.margin?.top ?? 0) + (props.properties.margin?.bottom ?? 0)).toString()}
onChange={(value) => props.onChange('height', Number(value) - (props.properties.margin?.top ?? 0) - (props.properties.margin?.bottom ?? 0))} /> onChange={(value) => props.onChange('height', Number(value) - (props.properties.margin?.top ?? 0) - (props.properties.margin?.bottom ?? 0))} />
<TextInputGroup <TextInputGroup
key={`${props.properties.id}-ml`}
labelText='Margin left' labelText='Margin left'
inputKey='left' inputKey='left'
labelClassName='' labelClassName=''
@ -144,6 +152,7 @@ export function ContainerForm(props: IContainerFormProps): JSX.Element {
value={(props.properties.margin.left ?? 0).toString()} value={(props.properties.margin.left ?? 0).toString()}
onChange={(value) => props.onChange('left', Number(value), PropertyType.Margin)} /> onChange={(value) => props.onChange('left', Number(value), PropertyType.Margin)} />
<TextInputGroup <TextInputGroup
key={`${props.properties.id}-mb`}
labelText='Margin bottom' labelText='Margin bottom'
inputKey='bottom' inputKey='bottom'
labelClassName='' labelClassName=''
@ -153,6 +162,7 @@ export function ContainerForm(props: IContainerFormProps): JSX.Element {
value={(props.properties.margin.bottom ?? 0).toString()} value={(props.properties.margin.bottom ?? 0).toString()}
onChange={(value) => props.onChange('bottom', Number(value), PropertyType.Margin)} /> onChange={(value) => props.onChange('bottom', Number(value), PropertyType.Margin)} />
<TextInputGroup <TextInputGroup
key={`${props.properties.id}-mt`}
labelText='Margin top' labelText='Margin top'
inputKey='top' inputKey='top'
labelClassName='' labelClassName=''
@ -162,6 +172,7 @@ export function ContainerForm(props: IContainerFormProps): JSX.Element {
value={(props.properties.margin.top ?? 0).toString()} value={(props.properties.margin.top ?? 0).toString()}
onChange={(value) => props.onChange('top', Number(value), PropertyType.Margin)} /> onChange={(value) => props.onChange('top', Number(value), PropertyType.Margin)} />
<TextInputGroup <TextInputGroup
key={`${props.properties.id}-mr`}
labelText='Margin right' labelText='Margin right'
inputKey='right' inputKey='right'
labelClassName='' labelClassName=''

View file

@ -1,6 +1,8 @@
import * as React from 'react'; import * as React from 'react';
interface ITextInputGroupProps { interface ITextInputGroupProps {
/** Use key the same way as React.Key */
key: string
labelKey?: string labelKey?: string
labelText: string labelText: string
inputKey: string inputKey: string
@ -22,7 +24,7 @@ export function TextInputGroup(props: ITextInputGroupProps): JSX.Element {
React.useEffect(() => { React.useEffect(() => {
setValue(props.value); setValue(props.value);
}, [props.value]); }, [props.value, props.key]);
function OnKeyUp(event: React.KeyboardEvent): void { function OnKeyUp(event: React.KeyboardEvent): void {
switch (event.key) { switch (event.key) {