Skip to content

Commit

Permalink
Partially revert (WordPress#39186) to restore update action
Browse files Browse the repository at this point in the history
  • Loading branch information
stokesman committed Apr 5, 2022
1 parent 41325b9 commit 825ab30
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/components/src/input-control/input-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function InputField(
pressEnter,
pressUp,
reset,
update,
} = useInputControlStateReducer( stateReducer, {
isDragEnabled,
value: valueProp,
Expand All @@ -90,7 +91,7 @@ function InputField(
return;
}
if ( ! isFocused && ! wasDirtyOnBlur.current ) {
commit( valueProp, _event as SyntheticEvent );
update( valueProp, _event as SyntheticEvent );
} else if ( ! isDirty ) {
onChange( value, {
event: _event as
Expand Down
8 changes: 7 additions & 1 deletion packages/components/src/input-control/reducer/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ 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 @@ -41,9 +42,14 @@ 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;
export type ChangeEventAction =
| ChangeAction
| ResetAction
| CommitAction
| UpdateAction;

export type DragEventAction = DragStartAction | DragEndAction | DragAction;

Expand Down
7 changes: 7 additions & 0 deletions packages/components/src/input-control/reducer/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ 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 @@ -192,6 +197,7 @@ 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 @@ -214,5 +220,6 @@ export function useInputControlStateReducer(
pressUp,
reset,
state,
update,
} as const;
}

0 comments on commit 825ab30

Please sign in to comment.