Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
fix(datepicker): prevent scrolling while calendar pane is open.
Browse files Browse the repository at this point in the history
  • Loading branch information
jelbourn committed Aug 13, 2015
1 parent d6457e2 commit e605373
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/components/datepicker/datePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// PRE RELEASE
// TODO(jelbourn): Documentation
// TODO(jelbourn): Demo that uses moment.js
// TODO(jelbourn): make sure this plays well with validation and ngMessages.

// POST RELEASE
// TODO(jelbourn): make sure this plays well with validation and ngMessages.
// TODO(jelbourn): calendar pane doesn't open up outside of visible viewport.
// TODO(jelbourn): forward more attributes to the internal input (required, autofocus, etc.)
// TODO(jelbourn): error state
Expand Down Expand Up @@ -307,6 +307,13 @@
this.attachCalendarPane();
this.focusCalendar();

// Because the calendar pane is attached directly to the body, it is possible that the
// rest of the component (input, etc) is in a different scrolling container, such as
// an md-content. This means that, if the container is scrolled, the pane would remain
// stationary. To remedy this, we disable scrolling while the calendar pane is open, which
// also matches the native behavior for things like `<select>` on Mac and Windows.
this.$mdUtil.disableScrollAround(this.calendarPane);

// Attach click listener inside of a timeout because, if this open call was triggered by a
// click, we don't want it to be immediately propogated up to the body and handled.
var self = this;
Expand All @@ -322,6 +329,8 @@
this.detachCalendarPane();
this.calendarPaneOpenedFrom.focus();
this.calendarPaneOpenedFrom = null;
this.$mdUtil.enableScrolling();

document.body.removeEventListener('click', this.bodyClickHandler);
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/datepicker/datePicker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $md-datepicker-open-animation-duration: 0.2s;
.md-datepicker-input {
@include md-flat-input();
min-width: 120px;
max-width: $md-calendar-width;
max-width: $md-calendar-width - $md-datepicker-button-gap;
}

// Container for the datepicker input.
Expand Down

0 comments on commit e605373

Please sign in to comment.