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
feat(datepicker): export NgbDatepickerMonthView component #3396
feat(datepicker): export NgbDatepickerMonthView component #3396
Conversation
@benouat @maxokorokov @ExFlo |
@gpolychronisamadeus haven't looked at it yet, but the build is failing (will restart the build to see if it wasn't a fluke) Also some description of what you're trying to do, why and providing some examples is always helpful to review. UPDATE: build worked, was a sauce labs fluke apparently. |
Codecov Report
@@ Coverage Diff @@
## master #3396 +/- ##
==========================================
+ Coverage 91.71% 91.74% +0.02%
==========================================
Files 100 100
Lines 2898 2907 +9
Branches 535 537 +2
==========================================
+ Hits 2658 2667 +9
Misses 183 183
Partials 57 57
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.
Hey, @gpolychronisamadeus!
Looks promising, thanks!
Big things that we should address:
- let's remove
NgbDatepickerMonth
and replace it with{month: number, year: number, day?: number}
for public API - maybe try move
registerMonthView
implementation completely from the datepicker to theNgbDatepickerMonthView
? - keyboard support not working for custom content template
- demo from the overview not working when I copy-paste it
- missing integration tests (ex. to check keyboard with custom template)
- we also have
NgbInputDatepicker
that should support this functionality, don't forget about it. We could do it in a separate PR, will just need to make sure it will work
Let's also in future support datepikcer.state.months[]
to get generated months directly!
demo/src/app/components/datepicker/overview/datepicker-overview.component.ts
Outdated
Show resolved
Hide resolved
@maxokorokov |
@gpolychronisamadeus I think it should be safe to rebase this on master now |
@maxokorokov |
9f53422
to
45cc80f
Compare
Will create a different PR or provide an alternative via demo example. Let's discuss on 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.
Hey, @gpolychronisamadeus!
As discussed there is a severe performance regression when changing months with keyboard when multiple months are visible → both memory impact and JS processing impact:
Before:
After:
You need to check where handlers are allocated / GCed, but especially DOM nodes. Looks like they're not reused as before.
Some ideas we had:
- don't override the whole content, but only the inside of the
<div class="dp-months">
- fix focusin/out handlers
Also left some comments:
- KeyboardService → Calendar dependency might not work as expected
- please check your code for unused imports, they're everywhere
const state = dp.state; | ||
switch (event.code) { | ||
case Key.PageUp: | ||
dp.focusDate(calendar.getPrev(state.focusedDate, event.altKey ? 'y' : 'm')); | ||
dp.focusDate(this.calendar.getPrev(state.focusedDate, event.altKey ? 'y' : 'm')); |
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.
Typescript is pretty unhappy with this.calendar
for some reason. Not sure why
@@ -10,18 +10,22 @@ import {Key} from '../util/key'; | |||
*/ | |||
@Injectable({providedIn: 'root'}) | |||
export class NgbDatepickerKeyboardService { | |||
constructor(private _calendar: NgbCalendar) {} |
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.
As KeyboardService
provided in root
, I wonder what will get injected when the calendar
is overridden at the datepicker component level ?
I guess it should be left as an argument to the processKey
function
src/datepicker/datepicker-service.ts
Outdated
@@ -151,6 +151,15 @@ export class NgbDatepickerService { | |||
return this._calendar.isValid(ngbDate) ? ngbDate : defaultValue; | |||
} | |||
|
|||
getMonth(struct: NgbDateStruct) { | |||
for (let viewModel of this._state.months) { |
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: maybe month
instead of viewModel
?
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 the input of NgbDatepickerMonthView. User might provide a an object with just the year and the month and not a proper NgbDate object.
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 was a nitpick and I was talking purely about the viewModel
variable name
src/datepicker/datepicker.ts
Outdated
@@ -91,6 +92,19 @@ export interface NgbDatepickerState { | |||
* The date currently focused by the datepicker | |||
*/ | |||
readonly focusedDate: NgbDate; | |||
|
|||
/** | |||
* The months in range of the datepicker |
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.
need more details here, not clear that dates are first dates for month
45cc80f
to
f5486ee
Compare
b4fcb49
to
e057fb9
Compare
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.
Hey, @gpolychronisamadeus!
I'd very much like to finish with this, but I've still seen these issues:
- performance. It's better now, but still not acceptable and needs more investigation (I'll try to allocate some time for it too)
Normal datepicker with 2 months:
Customised template with 2 months:
120Mb and 80K nodes still look excessive. Looks like they're garbage collected, but I'd like to understand the difference with the normal implementation.
-
please rebase
-
left a comment about keyboard
demo/src/app/components/datepicker/demos/keyboard/datepicker-keyboard.ts
Show resolved
Hide resolved
@maxokorokov I think this might help with performance. |
e057fb9
to
be44445
Compare
As discussed the following changes will have to be done:
Documentation issue will be fixed by an other commit. |
be44445
to
35b0403
Compare
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.
@gpolychronis one last small change → you changed the NgbDatepicker
constructor arguments for no reason, could you please rollback and I'll mark as to merge
?
35b0403
to
693bf0b
Compare
693bf0b
to
8ed67e2
Compare
As we've discussed:
Will merge when green |
Export NgbDatepickerMonthView component.
This component corresponds to the view of the days of a single month of the datepicker.
This export is an attempt to allow:
Code has been refactored, so that:
NgbDatepickerMonthView remains linked to an instance of a NgbDatepicker, to support the various functionalities it is accompanied with (i.e. i18n, focus, keyboard navigation etc.)