Skip to content

feat(material/datepicker): add support for cancel/apply buttons - #21487

Merged
annieyw merged 1 commit into
angular:masterfrom
crisbeto:COMP-316/datepicker-actions
Jan 9, 2021
Merged

feat(material/datepicker): add support for cancel/apply buttons#21487
annieyw merged 1 commit into
angular:masterfrom
crisbeto:COMP-316/datepicker-actions

Conversation

@crisbeto

@crisbeto crisbeto commented Jan 2, 2021

Copy link
Copy Markdown
Member

Adds support for projecting in "Cancel" and "Apply" buttons in mat-datepicker and mat-date-range-picker. Doing so will change the behavior of the datepicker so that the user has to explicitly accept a value after they've clicked on it. The consumption is as follows:

<mat-datepicker>
  <mat-datepicker-actions>
    <button mat-button matDatepickerCancel>Cancel</button>
    <button mat-raised-button color="primary" matDatepickerApply>Apply</button>
  </mat-datepicker-actions>
</mat-datepicker>

The result looks like this:
Example

@crisbeto crisbeto added P2 The issue is important to a large percentage of users, with a workaround target: minor This PR is targeted for the next minor release labels Jan 2, 2021
@google-cla google-cla Bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jan 2, 2021
selector: 'mat-datepicker-actions, mat-date-range-picker-actions',
styleUrls: ['datepicker-actions.css'],
template: `
<ng-template>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a way we could avoid doing the ng-content inside ng-template pattern? Doing this, Angular ends up instantiating the content even when it's not rendered. It could just be an ng-template-based API, or maybe just vanilla content projection?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We could, but I decided not to do it, because projecting a couple of buttons isn't particularly performance-intensive. Also using an ng-template to define the buttons doesn't allow for things like ngIf and ngFor to be used on the same element.

Comment thread src/material/datepicker/datepicker-content.html Outdated
@kseamon

kseamon commented Jan 5, 2021

Copy link
Copy Markdown
Contributor

LGTM

@jelbourn jelbourn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

FWIW on the .example thing- my main motivation for doing that is to make it clear which styles come from where (demo vs implementation) when inspecting the DOM in devtools.

@jelbourn jelbourn added the action: merge The PR is ready for merge by the caretaker label Jan 6, 2021
Adds support for projecting in "Cancel" and "Apply" buttons in `mat-datepicker` and
`mat-date-range-picker`. Doing so will change the behavior of the datepicker so that the user
has to explicitly accept a value after they've clicked on it. The consumption is as follows:

```
<mat-datepicker>
  <mat-datepicker-actions>
    <button mat-button matDatepickerCancel>Cancel</button>
    <button mat-raised-button color="primary" matDatepickerApply>Apply</button>
  </mat-datepicker-actions>
</mat-datepicker>
```
@crisbeto
crisbeto force-pushed the COMP-316/datepicker-actions branch from f251604 to 1af4631 Compare January 7, 2021 07:03
@annieyw
annieyw merged commit d590847 into angular:master Jan 9, 2021
wagnermaciel pushed a commit to wagnermaciel/components that referenced this pull request Jan 14, 2021
…lar#21487)

Adds support for projecting in "Cancel" and "Apply" buttons in `mat-datepicker` and
`mat-date-range-picker`. Doing so will change the behavior of the datepicker so that the user
has to explicitly accept a value after they've clicked on it. The consumption is as follows:

```
<mat-datepicker>
  <mat-datepicker-actions>
    <button mat-button matDatepickerCancel>Cancel</button>
    <button mat-raised-button color="primary" matDatepickerApply>Apply</button>
  </mat-datepicker-actions>
</mat-datepicker>
```
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Feb 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement P2 The issue is important to a large percentage of users, with a workaround target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants