-
Notifications
You must be signed in to change notification settings - Fork 64
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
Simplify widget render #336
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.
A few subjective observations / suggestions, but this is ready to land. I made #343 to track the removal of all other sub-widgets.
src/button/Button.ts
Outdated
@@ -70,6 +70,30 @@ export default class Button extends ButtonBase<ButtonProperties> { | |||
private _onTouchEnd (event: TouchEvent) { this.properties.onTouchEnd && this.properties.onTouchEnd(event); } | |||
private _onTouchCancel (event: TouchEvent) { this.properties.onTouchCancel && this.properties.onTouchCancel(event); } | |||
|
|||
protected getContent() { |
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.
It may be nice to embrace ES getters if no arguments are passed to these:
get content() {
return this.children;
}
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 say this is overkill @bitpshr especially if the getter
ends up doing more than simply getting.
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.
Fair.
src/calendar/tests/unit/Calendar.ts
Outdated
return w(CalendarCell, { | ||
key: `date-${dateIndex}`, | ||
key: `date-${date}${active ? '' : '-dimmed'}`, |
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.
Why was this change necessary?
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.
when I moved rendering the actual date cell into its own function (renderDateCell
), I didn't have access to the index any more. It seemed overkill to pass it in just for the key when I could also generate a unique key based on the date and currentMonth.
@@ -16,7 +16,6 @@ import * as iconCss from '../common/styles/icons.m.css'; | |||
* | |||
* Properties that can be set on a Calendar component | |||
* | |||
* @property CustomDateCell Custom widget constructor for the date cell. Should use CalendarCell as a base. |
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.
Did you remove sub-widgets as part of this PR as well?
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 problem is sub-widgets make it much easier to handle data binding on event handlers (e.g. onClick
on a specific date cell returns the correct date and disabled state). Based on talking with Ant, I think the compromise reached was to leave in sub-widgets, but try not to expose them to the user
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've been wondering if it makes sense to remove the typedoc for CalendarCell. It's marginally useful to developers wanting to extend CalendarCell, but I definitely don't want it showing up in Dojo documentation
src/button/Button.ts
Outdated
@@ -70,6 +70,30 @@ export default class Button extends ButtonBase<ButtonProperties> { | |||
private _onTouchEnd (event: TouchEvent) { this.properties.onTouchEnd && this.properties.onTouchEnd(event); } | |||
private _onTouchCancel (event: TouchEvent) { this.properties.onTouchCancel && this.properties.onTouchCancel(event); } | |||
|
|||
protected getContent() { |
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 say this is overkill @bitpshr especially if the getter
ends up doing more than simply getting.
src/calendar/Calendar.ts
Outdated
}); | ||
} | ||
|
||
protected renderPagingButtonContent(type: 'next' | 'previous') { |
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.
next
/ previous
would be better as a string enum
src/calendar/DatePicker.ts
Outdated
@@ -191,7 +191,38 @@ export default class DatePicker extends DatePickerBase<DatePickerProperties> { | |||
onPopupChange && onPopupChange(this._getPopupState()); | |||
} | |||
|
|||
private _renderMonthRadios() { | |||
protected renderControlsTrigger(type: 'month' | 'year'): DNode { |
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.
string enum
src/calendar/DatePicker.ts
Outdated
@@ -215,7 +246,20 @@ export default class DatePicker extends DatePickerBase<DatePickerProperties> { | |||
])); | |||
} | |||
|
|||
private _renderYearRadios() { | |||
protected renderPagingButtonContent(type: 'next' | 'previous') { |
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.
string enum
03c3dcc
to
aba806b
Compare
Codecov Report
@@ Coverage Diff @@
## master #336 +/- ##
==========================================
+ Coverage 98.9% 99.13% +0.22%
==========================================
Files 24 24
Lines 1740 1845 +105
Branches 462 467 +5
==========================================
+ Hits 1721 1829 +108
+ Misses 1 0 -1
+ Partials 18 16 -2
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #336 +/- ##
==========================================
+ Coverage 98.9% 99.03% +0.12%
==========================================
Files 24 24
Lines 1740 1866 +126
Branches 462 480 +18
==========================================
+ Hits 1721 1848 +127
+ Misses 1 0 -1
Partials 18 18
Continue to review full report at Codecov.
|
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.
Other than minor stuff, I think these new methods should have return types.
src/button/Button.ts
Outdated
@@ -70,6 +70,30 @@ export default class Button extends ButtonBase<ButtonProperties> { | |||
private _onTouchEnd (event: TouchEvent) { this.properties.onTouchEnd && this.properties.onTouchEnd(event); } | |||
private _onTouchCancel (event: TouchEvent) { this.properties.onTouchCancel && this.properties.onTouchCancel(event); } | |||
|
|||
protected getContent() { |
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 specify return types for these utility functions?
src/calendar/Calendar.ts
Outdated
const { renderWeekdayCell } = this.properties; | ||
return renderWeekdayCell ? renderWeekdayCell(day) : v('abbr', { title: day.long }, [ day.short ]); | ||
protected renderDateCell(date: number, selected: boolean, currentMonth: boolean, today: boolean): DNode { | ||
const key = currentMonth ? `date-${date}` : `date-${date}-dimmed`; |
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.
Should more/all the calculated values be extracted to the calling 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.
This matches up with the comment on the unit test where key
could be passed here so the renderDateCell
override doesn't need to care about how to come up with its own unique key
'aria-haspopup': 'true', | ||
id: `${this._idBase}_${type}_button`, | ||
classes: this.classes( | ||
(css as any)[`${type}Trigger`], |
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.
It would be nice to make this type safe, but I couldn't come up with a good solution that wouldn't add a ton of code.
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.
yeah, I chose concise code over css types in this particular case, but I was kinda ambivalent about it.
src/timepicker/TimePicker.ts
Outdated
} | ||
|
||
private _onNativeBlur(event: FocusEvent) { | ||
this.properties.onBlur && this.properties.onBlur((<HTMLInputElement> event.target).value); |
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.
You could add this interface and use this instead of FocusEvent
to clean things up a little.
interface FocusInputEvent extends FocusEvent {
target: HTMLInputElement;
}
role: 'heading' | ||
}, [ | ||
v('div', { | ||
v('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.
Why did this change to a 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.
I always thought it should be a button, since one of the basic a11y principles in our widget design is to use native elements whenever possible. I just took this widget pattern PR as a good place to change it. It also simplifies the code a ton, since we no longer need to handle focus and key events manually.
}, [ | ||
v('i', { |
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.
Why isn't this displayed anymore?
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.
it is, I just moved it to this.renderExpandIcon()
Type: feature
The following has been addressed in the PR:
Description:
Resolves #316
Makes widgets more easily extensible by simplifying the render code, particularly addressing these points from the issue: