-
Notifications
You must be signed in to change notification settings - Fork 734
Support rendering leading Icon to TextField #815
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
Changes from all commits
2068d80
5b2b2a7
4d6f9f3
435ad70
e112379
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,7 +125,7 @@ export default class TextField extends BaseInput { | |
*/ | ||
transformer: PropTypes.func, | ||
/** | ||
* Pass to render a prefix text as part of the input | ||
* Pass to render a prefix text as part of the input (doesn't work with floatingPlaceholder) | ||
*/ | ||
prefix: PropTypes.string, | ||
/** | ||
|
@@ -172,7 +172,11 @@ export default class TextField extends BaseInput { | |
iconColor: PropTypes.string, | ||
onPress: PropTypes.func, | ||
style: PropTypes.oneOfType([PropTypes.object, PropTypes.number]) | ||
}) | ||
}), | ||
/** | ||
* Pass to render a leading icon to the TextInput value. Accepts Image props (doesn't work with floatingPlaceholder) | ||
*/ | ||
leadingIcon: PropTypes.shape(Image.propTypes) | ||
}; | ||
|
||
static defaultProps = { | ||
|
@@ -310,8 +314,7 @@ export default class TextField extends BaseInput { | |
} | ||
|
||
getTopPaddings() { | ||
const {floatingPlaceholder} = this.getThemeProps(); | ||
return floatingPlaceholder ? (this.shouldShowTopError() ? undefined : 25) : undefined; | ||
return this.shouldFakePlaceholder() ? (this.shouldShowTopError() ? undefined : 25) : undefined; | ||
} | ||
|
||
isDisabled() { | ||
|
@@ -345,8 +348,9 @@ export default class TextField extends BaseInput { | |
} | ||
|
||
shouldFakePlaceholder() { | ||
const {floatingPlaceholder, centered} = this.getThemeProps(); | ||
return Boolean(floatingPlaceholder && !centered && !this.shouldShowTopError()); | ||
const {floatingPlaceholder, centered, leadingIcon, prefix} = this.getThemeProps(); | ||
|
||
return !leadingIcon && !prefix && Boolean(floatingPlaceholder && !centered && !this.shouldShowTopError()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not to allow leading icon and floatingPlaceholder?. Missing onLayout implementation for this of course (See relevant comment above). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was about to add it, but it caused a weird UI issue where the floating placeholder transition looked bad. |
||
} | ||
|
||
shouldShowError() { | ||
|
@@ -389,6 +393,9 @@ export default class TextField extends BaseInput { | |
style={[ | ||
this.styles.placeholder, | ||
typography, | ||
// TODO: we need to exclude completely any dependency on line height | ||
// in this component since it always breaks alignments | ||
{lineHeight: undefined}, | ||
{ | ||
transform: [ | ||
{ | ||
|
@@ -627,7 +634,7 @@ export default class TextField extends BaseInput { | |
} | ||
|
||
render() { | ||
const {expandable, containerStyle, underlineColor, useTopErrors, hideUnderline} = this.getThemeProps(); | ||
const {expandable, containerStyle, underlineColor, useTopErrors, hideUnderline, leadingIcon} = this.getThemeProps(); | ||
const underlineStateColor = this.getStateColor(underlineColor || UNDERLINE_COLOR_BY_STATE); | ||
|
||
return ( | ||
|
@@ -642,6 +649,7 @@ export default class TextField extends BaseInput { | |
{paddingTop: this.getTopPaddings()} | ||
]} | ||
> | ||
{leadingIcon && <Image {...leadingIcon}/>} | ||
{this.renderPrefix()} | ||
{this.renderPlaceholder()} | ||
{expandable ? this.renderExpandableInput() : this.renderTextInput()} | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
We don't want to supply a default margin and let it be overridden?
This forces to always supply a margin since it doesn't look good without 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.
I preferred to keep it clean as long as it doesn't look bad without custom styling.
This spacing is just for the sake of this example.
I assume we will pass something else in the private config