-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Custom Input Icon--calendar position #627
Conversation
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'm also wondering if perhaps we want an enum for inputIconPosition
that can be either "before" or "after", rather than a boolean?
src/components/DateRangePicker.jsx
Outdated
@@ -51,6 +51,7 @@ const defaultProps = { | |||
screenReaderInputMessage: '', | |||
showClearDates: false, | |||
showDefaultInputIcon: false, | |||
showInputIconRight: false, |
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.
Let's avoid using terms like "Right" - in an RTL world, "after" is more appropriate.
@@ -123,6 +126,18 @@ export default class DateRangePickerInput extends React.Component { | |||
}); | |||
} | |||
|
|||
renderInputIcon(inputIcon) { | |||
return (<button |
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 (
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.
@@ -89,6 +92,18 @@ export default class SingleDatePickerInput extends React.Component { | |||
}); | |||
} | |||
|
|||
renderInputIcon(inputIcon) { | |||
return (<button |
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.
indentation and prop destructuring here also
Thanks for your review, I've done the requested changes. |
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.
LGTM pending the last few comments.
@@ -45,6 +45,7 @@ const propTypes = forbidExtraProps({ | |||
readOnly: PropTypes.bool, | |||
showCaret: PropTypes.bool, | |||
showDefaultInputIcon: PropTypes.bool, | |||
inputIconPosition: PropTypes.oneOf('before', 'after'), |
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 should come from the shape, so that it doesn't have to be defined more than once
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.
DateRangePicker imports shape, but DateRangePickerInput and DateRangePickerInputController don't.. Do I have to change the complete structure?
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'm not sure you need to refactor much; newly importing the shape should be fine.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 :-)
@@ -123,6 +126,22 @@ export default class DateRangePickerInput extends React.Component { | |||
}); | |||
} | |||
|
|||
renderInputIcon(inputIcon) { | |||
const {disabled, phrases.focusStartDate, onArrowDown} = this.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.
curly braces in JS need padding spaces inside them - the linter should be failing here.
@@ -89,6 +92,22 @@ export default class SingleDatePickerInput extends React.Component { | |||
}); | |||
} | |||
|
|||
renderInputIcon(inputIcon) { | |||
const {disabled, phrases.focusStartDate, onFocus} = this.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.
also here
…an instance of array'
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 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!
src/components/DateRangePicker.jsx
Outdated
@@ -51,6 +51,7 @@ const defaultProps = { | |||
screenReaderInputMessage: '', | |||
showClearDates: false, | |||
showDefaultInputIcon: false, | |||
inputIconPosition: 'before', |
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 probably want to pull this 'before'/'after' into the constants file
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.
Now that we have the constants file, it'd be better to import that and use BEFORE_POSITION
here.
@@ -45,6 +45,7 @@ const propTypes = forbidExtraProps({ | |||
readOnly: PropTypes.bool, | |||
showCaret: PropTypes.bool, | |||
showDefaultInputIcon: PropTypes.bool, | |||
inputIconPosition: PropTypes.oneOf(['before', 'after']), |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)) && ( |
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.
same comment applies here
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, |
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.
Couple of comments! Sorry for the delay in reviewing!
src/components/DateRangePicker.jsx
Outdated
@@ -51,6 +51,7 @@ const defaultProps = { | |||
screenReaderInputMessage: '', | |||
showClearDates: false, | |||
showDefaultInputIcon: false, | |||
inputIconPosition: 'before', |
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.
Now that we have the constants file, it'd be better to import that and use BEFORE_POSITION
here.
constants.js
Outdated
@@ -10,6 +10,9 @@ module.exports = { | |||
VERTICAL_ORIENTATION: 'vertical', | |||
VERTICAL_SCROLLABLE: 'verticalScrollable', | |||
|
|||
BEFORE_POSITION: 'before', |
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.
Can we make this even more specific and call it ICON_BEFORE_POSITION
or something. even ICON_BEFORE
would be fine.
@@ -87,6 +90,7 @@ const defaultProps = { | |||
readOnly: false, | |||
showCaret: false, | |||
showDefaultInputIcon: false, | |||
inputIconPosition: 'before', |
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.
Same. Let's use the variable here.
@@ -109,6 +113,7 @@ export default class DateRangePickerInput extends React.Component { | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need to be bound.
@@ -123,6 +128,22 @@ export default class DateRangePickerInput extends React.Component { | |||
}); | |||
} | |||
|
|||
renderInputIcon(calendarIcon) { |
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'd rather have this as a variable inputIcon
in the render
method than its own method.
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.
Agreed: renderFoo
methods are generally an antipattern; could this be an SFC, or inline jsx, instead?
@@ -51,6 +54,7 @@ const defaultProps = { | |||
showCaret: false, | |||
showClearDate: false, | |||
showDefaultInputIcon: false, | |||
inputIconPosition: 'before', |
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.
same
src/components/SingleDatePicker.jsx
Outdated
@@ -47,6 +47,7 @@ const defaultProps = { | |||
screenReaderInputMessage: '', | |||
showClearDate: false, | |||
showDefaultInputIcon: false, | |||
inputIconPosition: 'before', |
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.
same
@@ -75,6 +79,7 @@ export default class SingleDatePickerInput extends React.Component { | |||
|
|||
this.onClearDateMouseEnter = this.onClearDateMouseEnter.bind(this); | |||
this.onClearDateMouseLeave = this.onClearDateMouseLeave.bind(this); | |||
this.renderInputIcon = this.renderInputIcon.bind(this); |
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.
doesn't need to be bound
@@ -89,6 +94,22 @@ export default class SingleDatePickerInput extends React.Component { | |||
}); | |||
} | |||
|
|||
renderInputIcon(calendarIcon) { |
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'd prefer this as a variable in the render
method
Done :) |
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.
A few more comments! We're almost there, I promise
constants.js
Outdated
@@ -10,6 +10,9 @@ module.exports = { | |||
VERTICAL_ORIENTATION: 'vertical', | |||
VERTICAL_SCROLLABLE: 'verticalScrollable', | |||
|
|||
ICON_BEFORE_POSITION: 'before', | |||
AFTER_POSITION: 'after', |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no spaces after {
or before }
@@ -249,6 +256,9 @@ export default class DateRangePickerInput extends React.Component { | |||
</div> | |||
</button> | |||
)} | |||
|
|||
{ inputIconPosition === 'after' && inputIcon } |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no spaces after { or before }
@@ -174,6 +184,9 @@ export default class SingleDatePickerInput extends React.Component { | |||
</div> | |||
</button> | |||
)} | |||
|
|||
{ inputIconPosition === 'after' && inputIcon } |
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.
nit: no spaces after { or before }
Also let's use ICON_AFTER_POSITION here.
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.
Shouldn't the spaces around brackets be linted..?
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.
ideally, but the linter is never the entirety of a codebase's style.
src/shapes/IconPositionShape.js
Outdated
|
||
import { | ||
ICON_BEFORE_POSITION, | ||
AFTER_POSITION, |
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.
ICON_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'.