-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Fix possibly mis-measured text width in DatePicker #320
Changes from all commits
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 |
---|---|---|
|
@@ -31,8 +31,9 @@ export class DatePickerCaption extends React.Component<IDatePickerCaptionProps, | |
private displayedMonthText: string; | ||
private displayedYearText: string; | ||
|
||
private monthArrow: HTMLElement; | ||
private yearArrow: HTMLElement; | ||
private containerElement: HTMLElement; | ||
private monthArrowElement: HTMLElement; | ||
private yearArrowElement: HTMLElement; | ||
|
||
public render() { | ||
const { date, locale, localeUtils, minDate, maxDate } = this.props; | ||
|
@@ -62,7 +63,10 @@ export class DatePickerCaption extends React.Component<IDatePickerCaptionProps, | |
|
||
const caretClasses = classNames("pt-icon-standard", "pt-icon-caret-down", Classes.DATEPICKER_CAPTION_CARET); | ||
return ( | ||
<div className={Classes.DATEPICKER_CAPTION}> | ||
<div | ||
className={Classes.DATEPICKER_CAPTION} | ||
ref={this.containerRefHandler} | ||
> | ||
<div className={Classes.DATEPICKER_CAPTION_SELECT}> | ||
<select | ||
className={Classes.DATEPICKER_MONTH_SELECT} | ||
|
@@ -101,16 +105,19 @@ export class DatePickerCaption extends React.Component<IDatePickerCaptionProps, | |
this.positionArrows(); | ||
} | ||
|
||
private monthArrowRefHandler = (r: HTMLElement) => this.monthArrow = r; | ||
private yearArrowRefHandler = (r: HTMLElement) => this.yearArrow = r; | ||
private containerRefHandler = (r: HTMLElement) => this.containerElement = r; | ||
private monthArrowRefHandler = (r: HTMLElement) => this.monthArrowElement = r; | ||
private yearArrowRefHandler = (r: HTMLElement) => this.yearArrowElement = r; | ||
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. unrelated: I would like to move to the following pattern for ref handlers: private refHandlers = {
container: (r: HTMLElement) => this.containerElement = r,
monthArrow: ...,
yearArrow: ...,
}; 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'm accumulating a list of major refactors to datetime code, for the new year... |
||
|
||
private positionArrows() { | ||
// pass our container element to the measureTextWidth utility to ensure | ||
// that we're measuring the width of text as sized within this component. | ||
const textClass = "pt-datepicker-caption-measure"; | ||
const monthWidth = Utils.measureTextWidth(this.displayedMonthText, textClass); | ||
this.monthArrow.setAttribute("style", `left:${monthWidth}`); | ||
const monthWidth = Utils.measureTextWidth(this.displayedMonthText, textClass, this.containerElement); | ||
this.monthArrowElement.setAttribute("style", `left:${monthWidth}`); | ||
|
||
const yearWidth = Utils.measureTextWidth(this.displayedYearText, textClass); | ||
this.yearArrow.setAttribute("style", `left:${yearWidth}`); | ||
const yearWidth = Utils.measureTextWidth(this.displayedYearText, textClass, this.containerElement); | ||
this.yearArrowElement.setAttribute("style", `left:${yearWidth}`); | ||
} | ||
|
||
private handleMonthSelectChange = (e: React.FormEvent<HTMLSelectElement>) => { | ||
|
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.
👍 great renames