Skip to content

Commit 8c9db1e

Browse files
committed
Fix #6592: InputOtp respect props.value change
1 parent 424a459 commit 8c9db1e

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

components/lib/datatable/TableBody.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,10 +607,10 @@ export const TableBody = React.memo(
607607
const { originalEvent: event } = e;
608608

609609
if (!isUnsyled && DomHandler.hasClass(event.target, 'p-datatable-reorderablerow-handle')) {
610-
event.currentTarget?.draggable = true;
611-
event.target?.draggable = false;
610+
event.currentTarget.draggable = true;
611+
event.target.draggable = false;
612612
} else {
613-
event.currentTarget?.draggable = false;
613+
event.currentTarget.draggable = false;
614614
}
615615

616616
if (allowRowDrag(e)) {

components/lib/inputotp/InputOtp.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useContext, useRef, useState } from 'react';
22
import { PrimeReactContext, ariaLabel } from '../api/Api';
33
import { useHandleStyle } from '../componentbase/ComponentBase';
4-
import { useMergeProps } from '../hooks/Hooks';
4+
import { useMergeProps, useUpdateEffect } from '../hooks/Hooks';
55
import { InputText } from '../inputtext/InputText';
66
import { ObjectUtils } from '../utils/Utils';
77
import { InputOtpBase } from './BaseInputOtp';
@@ -174,6 +174,12 @@ export const InputOtp = React.memo(
174174
}
175175
};
176176

177+
useUpdateEffect(() => {
178+
const value = props.value ? props.value?.toString()?.split?.('') : new Array(props.length);
179+
180+
setTokens(value);
181+
}, [props.value]);
182+
177183
const createInputElements = (remainingInputs) => {
178184
if (remainingInputs <= 0) {
179185
return [];
@@ -219,8 +225,9 @@ export const InputOtp = React.memo(
219225
},
220226
ptm('root')
221227
);
228+
const inputs = createInputElements(props.length);
222229

223-
return <div {...rootElementProps}>{createInputElements(props.length)}</div>;
230+
return <div {...rootElementProps}>{inputs}</div>;
224231
})
225232
);
226233

0 commit comments

Comments
 (0)