Skip to content

Commit

Permalink
Fix primefaces#6592: InputOtp respect props.value change
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed May 8, 2024
1 parent 424a459 commit 438b205
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions components/lib/datatable/TableBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,10 +607,10 @@ export const TableBody = React.memo(
const { originalEvent: event } = e;

if (!isUnsyled && DomHandler.hasClass(event.target, 'p-datatable-reorderablerow-handle')) {
event.currentTarget?.draggable = true;
event.target?.draggable = false;
event.currentTarget.draggable = true;
event.target.draggable = false;
} else {
event.currentTarget?.draggable = false;
event.currentTarget.draggable = false;
}

if (allowRowDrag(e)) {
Expand Down
8 changes: 7 additions & 1 deletion components/lib/inputotp/InputOtp.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useContext, useRef, useState } from 'react';
import { PrimeReactContext, ariaLabel } from '../api/Api';
import { useHandleStyle } from '../componentbase/ComponentBase';
import { useMergeProps } from '../hooks/Hooks';
import { useMergeProps, useUpdateEffect } from '../hooks/Hooks';
import { InputText } from '../inputtext/InputText';
import { ObjectUtils } from '../utils/Utils';
import { InputOtpBase } from './BaseInputOtp';
Expand Down Expand Up @@ -174,6 +174,12 @@ export const InputOtp = React.memo(
}
};

useUpdateEffect(() => {
const value = props.value ? props.value?.toString()?.split?.('') : new Array(props.length);

setTokens(value);
}, [props.value]);

const createInputElements = (remainingInputs) => {
if (remainingInputs <= 0) {
return [];
Expand Down

0 comments on commit 438b205

Please sign in to comment.