Skip to content

Commit

Permalink
[fields] Fix placeholder override
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle committed Mar 28, 2024
1 parent 8644e2a commit 9e1f1be
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export interface UseFieldV6ForwardedProps {
onClick?: React.MouseEventHandler;
onFocus?: () => void;
onPaste?: React.ClipboardEventHandler<HTMLDivElement>;
placeholder?: string;
}

interface UseFieldV6AdditionalProps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ export const useFieldV6TextField: UseFieldTextField<false> = (params) => {
const focusTimeoutRef = React.useRef<ReturnType<typeof setTimeout>>();

const {
forwardedProps: { onFocus, onClick, onPaste, onBlur, inputRef: inputRefProp },
forwardedProps: {
onFocus,
onClick,
onPaste,
onBlur,
inputRef: inputRefProp,
placeholder: inPlaceholder,
},
internalProps: { readOnly = false },
parsedSelectedSections,
activeSectionIndex,
Expand All @@ -100,6 +107,8 @@ export const useFieldV6TextField: UseFieldTextField<false> = (params) => {
localizedDigits,
} = params;

console.log(params);

const inputRef = React.useRef<HTMLInputElement>(null);
const handleRef = useForkRef(inputRefProp, inputRef);

Expand Down Expand Up @@ -381,15 +390,24 @@ export const useFieldV6TextField: UseFieldTextField<false> = (params) => {
applyCharacterEditing({ keyPressed, sectionIndex: activeSectionIndex });
});

const placeholder = React.useMemo(
() =>
fieldValueManager.getV6InputValueFromSections(
getSectionsFromValue(valueManager.emptyValue),
localizedDigits,
isRTL,
),
[fieldValueManager, getSectionsFromValue, valueManager.emptyValue, localizedDigits, isRTL],
);
const placeholder = React.useMemo(() => {
if (inPlaceholder) {
return inPlaceholder;
}

return fieldValueManager.getV6InputValueFromSections(
getSectionsFromValue(valueManager.emptyValue),
localizedDigits,
isRTL,
);
}, [
inPlaceholder,
fieldValueManager,
getSectionsFromValue,
valueManager.emptyValue,
localizedDigits,
isRTL,
]);

const valueStr = React.useMemo(
() =>
Expand Down

0 comments on commit 9e1f1be

Please sign in to comment.