Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

feat(datepicker): migrate to mdPanel #9641

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Sep 19, 2016

Migrates the datepicker's positioning logic to mdPanel. All the functionality should work as before.

Fixes #9564.

Notes

This PR technically works and it is ready for code review, however in order to achieve feature parity with the current datepicker we need the following:

@crisbeto crisbeto added needs: review This PR is waiting on review from the team Blocked Progress on this issue is blocked. Primarily used for PRs that are blocked by presubmit feedback. labels Sep 19, 2016
@crisbeto crisbeto force-pushed the 9564/datepicker-panel branch 8 times, most recently from 5b88abe to 3f6568c Compare September 20, 2016 16:16
crisbeto added a commit to crisbeto/material that referenced this pull request Sep 20, 2016
Prevents the panel from going outside the viewport by adjusting the position.
If developers want more control over how the panel gets repositioned, they can specify addition fallback positions via `addPanelPosition`.

Related to angular#9641.

Fixes angular#7878.
crisbeto added a commit to crisbeto/material that referenced this pull request Sep 20, 2016
Prevents the panel from going outside the viewport by adjusting the position.
If developers want more control over how the panel gets repositioned, they can specify addition fallback positions via `addPanelPosition`.

Related to angular#9641.

Fixes angular#7878.
crisbeto added a commit to crisbeto/material that referenced this pull request Sep 20, 2016
Prevents the panel from going outside the viewport by adjusting the position.
If developers want more control over how the panel gets repositioned, they can specify addition fallback positions via `addPanelPosition`.

Related to angular#9641.

Fixes angular#7878.
@ThomasBurleson ThomasBurleson added in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs and removed needs: review This PR is waiting on review from the team labels Sep 21, 2016
crisbeto added a commit to crisbeto/material that referenced this pull request Sep 21, 2016
Prevents the panel from going outside the viewport by adjusting the position.
If developers want more control over how the panel gets repositioned, they can specify addition fallback positions via `addPanelPosition`.

Related to angular#9641.

Fixes angular#7878.
if (this._panelRef) {
// Bind the keydown handler to the body, in order to handle cases where the focused
// element gets removed from the DOM and stops propagating key events.
angular.element(document.body).on('keydown', boundKeyHandler);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my first time looking at the date picker code. Can you explain what edge case this helps to prevent? Do other components care about this or have similar functionality?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The calendar currently focuses the active date's cell (I believe for accessibility reasons), which causes any keyboard events to be captured by the calendar. The issue is that the calendar uses mdVirtualRepeat which will remove the cell eventually, if you scroll long enough. This causes the browser to shift focus back to the body which stops the keyboard events from working.


/** @type {boolean} Whether the date-picker's calendar pane is open. */
/** @type {boolean} Whether the date-picker's calendar pane is open. Used internally. */
this.isCalendarOpen = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used internally, therefore should be marked private?

this.isOpen = false;

/** @type {boolean} Used to prevent infinite loops when using mdOpenOnFocus. */
this.preventInputFocus = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're using panels focusOnOpen, is this needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is also a private property. When the calendar closes, it restores focus to the element that triggered it to open. With mdOpenOnFocus that would cause the calendar to open up again since it refocuses the input. We use this flag to prevent such cases. It used to be possible to do this by delaying the close handler, but it got a little trickier with mdPanel since it's also async.

clickOutsideToClose: true,
escapeToClose: true,
focusOnOpen: false,
scope: this.$scope.$new(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the default, so you can remove it if you want. Being explicit is also fine though. Up to you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default creates a scope that's a child of $rootScope, however we need it to be a child of the datepicker's scope.

width: (elementRect.width - 1) + 'px',
height: (elementRect.height - 2) + 'px'
});
var self = this;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So much code goes bye-bye. This is amazing!

calendarPane.style.left = paneLeft + 'px';
calendarPane.style.top = paneTop + 'px';
document.body.appendChild(calendarPane);
// TODO(crisbeto): this should use getPanelYOffset once we ditch the units
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be done now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's waiting on #9609 to be merged.

@crisbeto crisbeto added the needs: rebase This PR needs to be rebased on the latest commits from master and conflicts need to be resolved label Sep 26, 2016
crisbeto added a commit to crisbeto/material that referenced this pull request Sep 26, 2016
Prevents the panel from going outside the viewport by adjusting the position.
If developers want more control over how the panel gets repositioned, they can specify addition fallback positions via `addPanelPosition`.

Related to angular#9641.

Fixes angular#7878.
@crisbeto crisbeto removed the needs: rebase This PR needs to be rebased on the latest commits from master and conflicts need to be resolved label Sep 26, 2016
.addPanelPosition($mdPanel.xPosition.ALIGN_START, $mdPanel.yPosition.ALIGN_TOPS)
.withOffsetX(-this.leftMargin + 'px')
.withOffsetY(angular.bind(this, this.getPanelYOffset));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current version of the md-datepicker hides the popup when the window is re-sized. I noticed that the md-panel stays in the original position when the window is resized and using "relativeTo" (it stops being relativeTo the original element).

Can you confirm what the behavior is for the new implementation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will still hide on resize (see https://github.com/angular/material/pull/9641/files#diff-31bf126782bc06608d149fe72237bf4eR702), although now it might be a little more practical to update the position instead. mdPanel has a convenient updatePosition method.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I see it know... (window.addEventListener(this.windowEventName, this.windowEventHandler) ). Thank you.

kara pushed a commit that referenced this pull request Oct 16, 2016
Prevents the panel from going outside the viewport by adjusting the position.
If developers want more control over how the panel gets repositioned, they can specify addition fallback positions via `addPanelPosition`.

Related to #9641.

Fixes #7878.
crisbeto added a commit to crisbeto/material that referenced this pull request Jan 1, 2017
Previously, if a panel had a position with an offset (e.g. `$mdPanel.newPanelPosition().center()`), the positioning would break any `transform` animations on the panel. This was due to the fact that `mdPanel` uses inline `transform` styles to do the offsetting. These changes introduce a wrapper around the panel (`.md-panel-inner-wrapper`), which will handle all of the positioning, allowing for any animations to be applied to the `.md-panel` itself.

Relates to angular#9641.
Fixes angular#9905.
crisbeto added a commit to crisbeto/material that referenced this pull request Jan 1, 2017
Previously, if a panel had a position with an offset (e.g. `$mdPanel.newPanelPosition().center()`), the positioning would break any `transform` animations on the panel. This was due to the fact that `mdPanel` uses inline `transform` styles to do the offsetting. These changes introduce a wrapper around the panel (`.md-panel-inner-wrapper`), which will handle all of the positioning, allowing for any animations to be applied to the `.md-panel` itself.

Relates to angular#9641.
Fixes angular#9905.
@ThomasBurleson ThomasBurleson modified the milestones: 1.1.3, 1.2.0 Jan 3, 2017
crisbeto added a commit to crisbeto/material that referenced this pull request May 10, 2017
Previously, if a panel had a position with an offset (e.g. `$mdPanel.newPanelPosition().center()`), the positioning would break any `transform` animations on the panel. This was due to the fact that `mdPanel` uses inline `transform` styles to do the offsetting. These changes introduce a wrapper around the panel (`.md-panel-inner-wrapper`), which will handle all of the positioning, allowing for any animations to be applied to the `.md-panel` itself.

Relates to angular#9641.
Fixes angular#9905.
@Splaktar Splaktar added P2: required Issues that must be fixed. a11y This issue is related to accessibility needs: rebase This PR needs to be rebased on the latest commits from master and conflicts need to be resolved labels Feb 7, 2018
@Splaktar Splaktar assigned Splaktar and unassigned ThomasBurleson and bradrich Feb 7, 2018
crisbeto added a commit to crisbeto/material that referenced this pull request Feb 7, 2018
Previously, if a panel had a position with an offset (e.g. `$mdPanel.newPanelPosition().center()`), the positioning would break any `transform` animations on the panel. This was due to the fact that `mdPanel` uses inline `transform` styles to do the offsetting. These changes introduce a wrapper around the panel (`.md-panel-inner-wrapper`), which will handle all of the positioning, allowing for any animations to be applied to the `.md-panel` itself.

Relates to angular#9641.
Fixes angular#9905.
Splaktar pushed a commit that referenced this pull request Jul 31, 2018
Previously, if a panel had a position with an offset (e.g. `$mdPanel.newPanelPosition().center()`), the positioning would break any `transform` animations on the panel. This was due to the fact that `mdPanel` uses inline `transform` styles to do the offsetting. These changes introduce a wrapper around the panel (`.md-panel-inner-wrapper`), which will handle all of the positioning, allowing for any animations to be applied to the `.md-panel` itself.

Relates to #9641.
Fixes #9905.
@Splaktar Splaktar modified the milestones: Future, 1.2.0 Jul 31, 2018
@Splaktar Splaktar added g3: reported The issue was reported by an internal or external product team. hotlist: animations labels Feb 12, 2019
@Splaktar Splaktar added this to In-Progress in Panel Refactors Mar 7, 2020
Splaktar pushed a commit that referenced this pull request May 15, 2020
Previously, if a panel had a position with an offset (e.g. `$mdPanel.newPanelPosition().center()`), the positioning would break any `transform` animations on the panel. This was due to the fact that `mdPanel` uses inline `transform` styles to do the offsetting. These changes introduce a wrapper around the panel (`.md-panel-inner-wrapper`), which will handle all of the positioning, allowing for any animations to be applied to the `.md-panel` itself.

Relates to #9641.
Fixes #9905.
Splaktar pushed a commit that referenced this pull request Jun 16, 2020
Previously, if a panel had a position with an offset (e.g. `$mdPanel.newPanelPosition().center()`), the positioning would break any `transform` animations on the panel. This was due to the fact that `mdPanel` uses inline `transform` styles to do the offsetting. These changes introduce a wrapper around the panel (`.md-panel-inner-wrapper`), which will handle all of the positioning, allowing for any animations to be applied to the `.md-panel` itself.

Relates to #9641.
Fixes #9905.
Splaktar pushed a commit that referenced this pull request Jun 17, 2020
Previously, if a panel had a position with an offset (e.g. `$mdPanel.newPanelPosition().center()`), the positioning would break any `transform` animations on the panel. This was due to the fact that `mdPanel` uses inline `transform` styles to do the offsetting. These changes introduce a wrapper around the panel (`.md-panel-inner-wrapper`), which will handle all of the positioning, allowing for any animations to be applied to the `.md-panel` itself.

Relates to #9641.
Fixes #9905.
@Splaktar Splaktar removed the Blocked Progress on this issue is blocked. Primarily used for PRs that are blocked by presubmit feedback. label Jun 17, 2020
@Splaktar Splaktar modified the milestones: 1.2.0, 1.3.0 Jul 30, 2020
@Splaktar Splaktar moved this from In-Progress to Rejected in Panel Refactors Dec 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a11y This issue is related to accessibility g3: reported The issue was reported by an internal or external product team. hotlist: animations in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs needs: rebase This PR needs to be rebased on the latest commits from master and conflicts need to be resolved P2: required Issues that must be fixed.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

datepicker: migrate to use mdPanel container
6 participants