Skip to content

Commit

Permalink
Fix primefaces#4351: InputText float label issue with controlled vs u…
Browse files Browse the repository at this point in the history
…ncontrolled
  • Loading branch information
melloware committed May 8, 2023
1 parent 3a60f18 commit 1cf4ebd
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions components/lib/inputtext/InputText.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { KeyFilter } from '../keyfilter/KeyFilter';
import { Tooltip } from '../tooltip/Tooltip';
import { classNames, DomHandler, ObjectUtils } from '../utils/Utils';
import { DomHandler, ObjectUtils, classNames } from '../utils/Utils';
import { InputTextBase } from './InputTextBase';

export const InputText = React.memo(
Expand All @@ -27,6 +27,7 @@ export const InputText = React.memo(

props.onInput && props.onInput(event, validatePattern);

// for uncontrolled changes
if (!props.onChange) {
const target = event.target;

Expand All @@ -42,13 +43,11 @@ export const InputText = React.memo(
}
};

const currentValue = elementRef.current && elementRef.current.value;
const isFilled = React.useMemo(() => ObjectUtils.isNotEmpty(props.value) || ObjectUtils.isNotEmpty(props.defaultValue) || ObjectUtils.isNotEmpty(currentValue), [props.value, props.defaultValue, currentValue]);

React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

const isFilled = React.useMemo(() => ObjectUtils.isNotEmpty(props.value) || ObjectUtils.isNotEmpty(props.defaultValue), [props.value, props.defaultValue]);
const hasTooltip = ObjectUtils.isNotEmpty(props.tooltip);
const otherProps = InputTextBase.getOtherProps(props);
const className = classNames(
Expand Down

0 comments on commit 1cf4ebd

Please sign in to comment.