This repository was archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
fix(Input): changing the default styles for Input component #25
Closed
Closed
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cd1aba6
changing the default styles for Input component
alinais d62e2f6
updating changelog
2125308
updating input component classes to be compatible with Edge browser
alinais 60739ac
fixing the input focus issue when clicking on the icon
alinais 40a3f05
cleaning the code
alinais 620bbf8
updating the icon overrides
alinais 598c63e
fixing minor description issue
alinais File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ import { | |
| import inputRules from './inputRules' | ||
| import inputVariables from './inputVariables' | ||
| import Icon from '../Icon' | ||
| import callable from '../../lib/callable' | ||
|
|
||
| /** | ||
| * An Input | ||
|
|
@@ -54,11 +55,20 @@ class Input extends UIComponent<any, any> { | |
| type: 'text', | ||
| } | ||
|
|
||
| inputRef: any | ||
|
|
||
| computeTabIndex = props => { | ||
| if (!_.isNil(props.tabIndex)) return props.tabIndex | ||
| if (props.onClick) return 0 | ||
| } | ||
|
|
||
| handleChildOverrides = (child, defaultProps) => ({ | ||
| ...defaultProps, | ||
| ...child.props, | ||
| }) | ||
|
|
||
| handleInputRef = c => (this.inputRef = c) | ||
|
|
||
| partitionProps = () => { | ||
| const { type } = this.props | ||
|
|
||
|
|
@@ -69,6 +79,7 @@ class Input extends UIComponent<any, any> { | |
| { | ||
| ...htmlInputProps, | ||
| type, | ||
| onClick: () => this.inputRef.focus(), | ||
| }, | ||
| rest, | ||
| ] | ||
|
|
@@ -81,11 +92,18 @@ class Input extends UIComponent<any, any> { | |
| return null | ||
| } | ||
|
|
||
| handleIconOverrides = predefinedProps => { | ||
| return { | ||
| tabIndex: this.computeTabIndex, | ||
| } | ||
| } | ||
|
|
||
| renderComponent({ ElementType, classes, rest }) { | ||
| const { children, className, icon, input, type } = this.props | ||
| const [htmlInputProps, restProps] = this.partitionProps() | ||
|
|
||
| const inputClasses = cx(classes.input) | ||
| const iconClasses = cx(classes.icon) | ||
|
|
||
| // Render with children | ||
| // ---------------------------------------- | ||
|
|
@@ -108,9 +126,15 @@ class Input extends UIComponent<any, any> { | |
| <ElementType {...rest} className={classes.root} {...htmlInputProps}> | ||
| {createHTMLInput(input || type, { | ||
| defaultProps: htmlInputProps, | ||
|
||
| overrideProps: { className: inputClasses }, | ||
| overrideProps: { | ||
| className: inputClasses, | ||
| ref: this.handleInputRef, | ||
| }, | ||
| })} | ||
| {Icon.create(this.computeIcon(), { | ||
| defaultProps: { className: iconClasses }, | ||
| overrideProps: predefinedProps => this.handleIconOverrides, | ||
| })} | ||
| <Icon name={this.computeIcon()} /> | ||
| </ElementType> | ||
| ) | ||
| } | ||
|
|
@@ -119,7 +143,10 @@ class Input extends UIComponent<any, any> { | |
| <ElementType {...rest} className={classes.root} {...htmlInputProps}> | ||
| {createHTMLInput(input || type, { | ||
| defaultProps: htmlInputProps, | ||
| overrideProps: { className: inputClasses }, | ||
| overrideProps: { | ||
| className: inputClasses, | ||
| ref: this.handleInputRef, | ||
| }, | ||
| })} | ||
| </ElementType> | ||
| ) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
No need for using cx here, as the classes are already calculated and we are not combining multiple object to classes.
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.
fixed