Custom Input Icon--calendar position#627
Custom Input Icon--calendar position#627majapw merged 11 commits intoreact-dates:masterfrom mariepw:CustomPositionIcon
Conversation
ljharb
left a comment
There was a problem hiding this comment.
I'm also wondering if perhaps we want an enum for inputIconPosition that can be either "before" or "after", rather than a boolean?
| screenReaderInputMessage: '', | ||
| showClearDates: false, | ||
| showDefaultInputIcon: false, | ||
| showInputIconRight: false, |
There was a problem hiding this comment.
Let's avoid using terms like "Right" - in an RTL world, "after" is more appropriate.
| } | ||
|
|
||
| renderInputIcon(inputIcon) { | ||
| return (<button |
There was a problem hiding this comment.
the ( should end the line, and the ) should begin the line - iow:
return (
<button
type="button"
className="DateRangePickerInput__calendar-icon"
disabled={this.props.disabled}
aria-label={this.props.phrases.focusStartDate}
onClick={this.props.onArrowDown}
>
{inputIcon}
</button>
);Also, please destructure all props at the top of the function.
| } | ||
|
|
||
| renderInputIcon(inputIcon) { | ||
| return (<button |
There was a problem hiding this comment.
indentation and prop destructuring here also
|
Thanks for your review, I've done the requested changes. |
ljharb
left a comment
There was a problem hiding this comment.
LGTM pending the last few comments.
| readOnly: PropTypes.bool, | ||
| showCaret: PropTypes.bool, | ||
| showDefaultInputIcon: PropTypes.bool, | ||
| inputIconPosition: PropTypes.oneOf('before', 'after'), |
There was a problem hiding this comment.
this should come from the shape, so that it doesn't have to be defined more than once
There was a problem hiding this comment.
DateRangePicker imports shape, but DateRangePickerInput and DateRangePickerInputController don't.. Do I have to change the complete structure?
There was a problem hiding this comment.
I'm not sure you need to refactor much; newly importing the shape should be fine.
There was a problem hiding this comment.
SimpleDatePickerShape/SimpleDatePicker and DateRangePickerShape/DateRangePicker share same props..
But DateRangePickerInputController SimpleDatePicker DateRangePickerInput, they all have their own props, which are quite different from parents [..Shape and ..Picker]..
I think shape files have props that input ones don't need..
But maybe I miss something, will investigate a bit more..
There was a problem hiding this comment.
There's a couple alternatives here; one is importing the shape but only extracting the one propType - another is putting this propType in its own file, and importing that in all the places it's needed. I'd prefer that approach tbh :-)
| } | ||
|
|
||
| renderInputIcon(inputIcon) { | ||
| const {disabled, phrases.focusStartDate, onArrowDown} = this.props; |
There was a problem hiding this comment.
curly braces in JS need padding spaces inside them - the linter should be failing here.
| } | ||
|
|
||
| renderInputIcon(inputIcon) { | ||
| const {disabled, phrases.focusStartDate, onFocus} = this.props; |
…an instance of array'
majapw
left a comment
There was a problem hiding this comment.
I think we should pull before, after, and the prop type into reusable variables. :) I also have a few nits about code duplication. O/w this is looking great!
| screenReaderInputMessage: '', | ||
| showClearDates: false, | ||
| showDefaultInputIcon: false, | ||
| inputIconPosition: 'before', |
There was a problem hiding this comment.
we probably want to pull this 'before'/'after' into the constants file
There was a problem hiding this comment.
Now that we have the constants file, it'd be better to import that and use BEFORE_POSITION here.
| readOnly: PropTypes.bool, | ||
| showCaret: PropTypes.bool, | ||
| showDefaultInputIcon: PropTypes.bool, | ||
| inputIconPosition: PropTypes.oneOf(['before', 'after']), |
There was a problem hiding this comment.
Since we reuse this, we probably want to save this as a shape, similar to OrientationShape
| {inputIcon} | ||
| </button> | ||
|
|
||
| {(inputIconPosition === 'before' && (showDefaultInputIcon || customInputIcon !== null)) && ( |
There was a problem hiding this comment.
We could probably pull (showDefaultInputIcon || customInputIcon !== null) && this.renderInputIcon(inputIcon) into a variable above the return and then just have inputIconPosition === 'before' && inputIcon
| > | ||
| {inputIcon} | ||
| </button> | ||
| {(inputIconPosition === 'before' && (showDefaultInputIcon || customInputIcon !== null)) && ( |
|
Build doesn't seem to fail because of my changes... |
|
@ljharb this actually appears to be failing due to some extraneous dependencies being installed after we attempt to install the relevant react version: Do you have any idea what might be going on with that? Do we need to explicitly remove those as well? That seems... weird. |
|
I think the short term fix might be to temporarily remove the |
|
Everything should be ok now ? |
|
Hi, |
majapw
left a comment
There was a problem hiding this comment.
Couple of comments! Sorry for the delay in reviewing!
| screenReaderInputMessage: '', | ||
| showClearDates: false, | ||
| showDefaultInputIcon: false, | ||
| inputIconPosition: 'before', |
There was a problem hiding this comment.
Now that we have the constants file, it'd be better to import that and use BEFORE_POSITION here.
| VERTICAL_ORIENTATION: 'vertical', | ||
| VERTICAL_SCROLLABLE: 'verticalScrollable', | ||
|
|
||
| BEFORE_POSITION: 'before', |
There was a problem hiding this comment.
Can we make this even more specific and call it ICON_BEFORE_POSITION or something. even ICON_BEFORE would be fine.
| readOnly: false, | ||
| showCaret: false, | ||
| showDefaultInputIcon: false, | ||
| inputIconPosition: 'before', |
There was a problem hiding this comment.
Same. Let's use the variable here.
|
|
||
| this.onClearDatesMouseEnter = this.onClearDatesMouseEnter.bind(this); | ||
| this.onClearDatesMouseLeave = this.onClearDatesMouseLeave.bind(this); | ||
| this.renderInputIcon = this.renderInputIcon.bind(this); |
There was a problem hiding this comment.
This doesn't need to be bound.
| }); | ||
| } | ||
|
|
||
| renderInputIcon(calendarIcon) { |
There was a problem hiding this comment.
I'd rather have this as a variable inputIcon in the render method than its own method.
There was a problem hiding this comment.
Agreed: renderFoo methods are generally an antipattern; could this be an SFC, or inline jsx, instead?
| showCaret: false, | ||
| showClearDate: false, | ||
| showDefaultInputIcon: false, | ||
| inputIconPosition: 'before', |
| screenReaderInputMessage: '', | ||
| showClearDate: false, | ||
| showDefaultInputIcon: false, | ||
| inputIconPosition: 'before', |
|
|
||
| this.onClearDateMouseEnter = this.onClearDateMouseEnter.bind(this); | ||
| this.onClearDateMouseLeave = this.onClearDateMouseLeave.bind(this); | ||
| this.renderInputIcon = this.renderInputIcon.bind(this); |
| }); | ||
| } | ||
|
|
||
| renderInputIcon(calendarIcon) { |
There was a problem hiding this comment.
I'd prefer this as a variable in the render method
|
Done :) |
majapw
left a comment
There was a problem hiding this comment.
A few more comments! We're almost there, I promise
| VERTICAL_SCROLLABLE: 'verticalScrollable', | ||
|
|
||
| ICON_BEFORE_POSITION: 'before', | ||
| AFTER_POSITION: 'after', |
There was a problem hiding this comment.
sorry and can we make this one ICON_AFTER_POSITION as well?
| </button> | ||
| )} | ||
|
|
||
| { inputIconPosition === ICON_BEFORE_POSITION && inputIcon } |
There was a problem hiding this comment.
nit: no spaces after { or before }
| </button> | ||
| )} | ||
|
|
||
| { inputIconPosition === 'after' && inputIcon } |
There was a problem hiding this comment.
nit: no spaces after { or before }
Also let's use ICON_AFTER_POSITION here.
| </button> | ||
| )} | ||
|
|
||
| { inputIconPosition === ICON_BEFORE_POSITION && inputIcon } |
There was a problem hiding this comment.
nit: no spaces after { or before }
| </button> | ||
| )} | ||
|
|
||
| { inputIconPosition === 'after' && inputIcon } |
There was a problem hiding this comment.
nit: no spaces after { or before }
Also let's use ICON_AFTER_POSITION here.
There was a problem hiding this comment.
Shouldn't the spaces around brackets be linted..?
There was a problem hiding this comment.
ideally, but the linter is never the entirety of a codebase's style.
|
|
||
| import { | ||
| ICON_BEFORE_POSITION, | ||
| AFTER_POSITION, |
…ant + Use constant instead of string
|
Sorry for my oversight, I've done the changes.. |
|
I'm just wondering if this has been implemented already. If so, how can this be used as this is not part of the latest docs. Thanks |
|
Could you file a new issue about the lack of docs? |
Hi @majapw, Hi all,
I implemented the changes proposed in #625 by adding prop 'showInputIconRight' to 'SingleDatePicker' and 'DateRangePicker'.