-
Notifications
You must be signed in to change notification settings - Fork 734
Incubator.TextField - should float with defaultValue #2344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incubator.TextField - should float with defaultValue #2344
Conversation
testID | ||
}: FloatingPlaceholderProps) => { | ||
const context = useContext(FieldContext); | ||
const [placeholderOffset, setPlaceholderOffset] = useState({ | ||
top: 0, | ||
left: 0 | ||
}); | ||
const animation = useRef(new Animated.Value(Number((floatOnFocus && context.isFocused) || context.hasValue))).current; | ||
|
||
const shouldFloat = useMemo(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to memoize primitive values (booleans, strings, etc...) 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't that break the useDidUpdate
dependencies? Unless I put the dependencies from here, which is a little weird.
I think we tested it once, but I can test again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right but I found a bug :/
@@ -86,6 +86,7 @@ export interface FloatingPlaceholderProps { | |||
floatOnFocus?: boolean; | |||
validationMessagePosition?: ValidationMessagePosition; | |||
extraOffset?: number; | |||
defaultValue?: TextInputProps['defaultValue']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'TextInputProps' are the OLD TextField's prop... why use them in the incubator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's RN's props
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok...
@@ -125,6 +125,7 @@ const TextField = (props: InternalTextFieldProps) => { | |||
<View flexG /* flex row */> | |||
{floatingPlaceholder && ( | |||
<FloatingPlaceholder | |||
defaultValue={others.defaultValue} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not pass the input's 'value'? Why do we need a separate prop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a prop from RN which we inherit and the user that opened the bug is using
@@ -18,24 +19,27 @@ const FloatingPlaceholder = ({ | |||
floatOnFocus, | |||
validationMessagePosition, | |||
extraOffset = 0, | |||
defaultValue, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The FlotingPlaceholder only needs to know only if to float or not, why doesn't the TextField component controls it with the 'hasValue' passed in context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're saying that shouldFloat
should be coming from somewhere else? Maybe the Presenter
like in ValidationMessage
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I think the floating placeholder should only get a boolean and the logic will be in the component that uses it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Description
Incubator.TextField - FloatingPlaceholder should float with defaultValue
Adding
shouldFloat
and fixing its logicWOAUILIB-3123
Handling edge cases, using the below
PlaygroundScreen
:TextField
s should:a. float\un-float if both are empty
b. float\un-float on an empty one and remain un-floated on one with a
value
\defaultValue
defaultValue
should affect the floating statusdefaultValue
(to an emptyvalue
) should un-floatChangelog
Incubator.TextField - FloatingPlaceholder should float with defaultValue