Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove UPDATE action from InputControl s state reducer
  • Loading branch information
ciampo committed Mar 17, 2022
commit a1c6fc78672431b0b1fd35ac99d59eb1dba69fc6
3 changes: 1 addition & 2 deletions packages/components/src/input-control/input-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ function InputField(
pressEnter,
pressUp,
reset,
update,
} = useInputControlStateReducer( stateReducer, {
isDragEnabled,
value: valueProp,
Expand All @@ -91,7 +90,7 @@ function InputField(
return;
}
if ( ! isFocused && ! wasDirtyOnBlur.current ) {
update( valueProp, _event as SyntheticEvent );
commit( valueProp, _event as SyntheticEvent );
} else if ( ! isDirty ) {
onChange( value, {
event: _event as ChangeEvent< HTMLInputElement >,
Expand Down
8 changes: 1 addition & 7 deletions packages/components/src/input-control/reducer/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const PRESS_DOWN = 'PRESS_DOWN';
export const PRESS_ENTER = 'PRESS_ENTER';
export const PRESS_UP = 'PRESS_UP';
export const RESET = 'RESET';
export const UPDATE = 'UPDATE';

interface EventPayload {
event?: SyntheticEvent;
Expand All @@ -42,14 +41,9 @@ export type DragStartAction = Action< typeof DRAG_START, DragProps >;
export type DragEndAction = Action< typeof DRAG_END, DragProps >;
export type DragAction = Action< typeof DRAG, DragProps >;
export type ResetAction = Action< typeof RESET, Partial< ValuePayload > >;
export type UpdateAction = Action< typeof UPDATE, ValuePayload >;
export type InvalidateAction = Action< typeof INVALIDATE, { error: unknown } >;

export type ChangeEventAction =
| ChangeAction
| ResetAction
| CommitAction
| UpdateAction;
export type ChangeEventAction = ChangeAction | ResetAction | CommitAction;

export type DragEventAction = DragStartAction | DragEndAction | DragAction;

Expand Down
7 changes: 0 additions & 7 deletions packages/components/src/input-control/reducer/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ function inputControlStateReducer(
nextState.value = action.payload.value || state.initialValue;
break;

case actions.UPDATE:
nextState.value = action.payload.value;
nextState.isDirty = false;
break;

/**
* Validation
*/
Expand Down Expand Up @@ -197,7 +192,6 @@ export function useInputControlStateReducer(
dispatch( { type: actions.INVALIDATE, payload: { error, event } } );
const reset = createChangeEvent( actions.RESET );
const commit = createChangeEvent( actions.COMMIT );
const update = createChangeEvent( actions.UPDATE );

const dragStart = createDragEvent( actions.DRAG_START );
const drag = createDragEvent( actions.DRAG );
Expand All @@ -220,6 +214,5 @@ export function useInputControlStateReducer(
pressUp,
reset,
state,
update,
} as const;
}
3 changes: 1 addition & 2 deletions packages/components/src/number-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ export function NumberControl(
*/
if (
type === inputControlActionTypes.PRESS_ENTER ||
type === inputControlActionTypes.COMMIT ||
type === inputControlActionTypes.UPDATE
type === inputControlActionTypes.COMMIT
) {
const applyEmptyValue = required === false && currentValue === '';

Expand Down