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 8c9db1e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 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
11 changes: 9 additions & 2 deletions 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 Expand Up @@ -219,8 +225,9 @@ export const InputOtp = React.memo(
},
ptm('root')
);
const inputs = createInputElements(props.length);

return <div {...rootElementProps}>{createInputElements(props.length)}</div>;
return <div {...rootElementProps}>{inputs}</div>;
})
);

Expand Down

0 comments on commit 8c9db1e

Please sign in to comment.