Skip to content

feat(cdk/menu): Allow setting cdkMenuTriggerFor null #25818

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

Merged
merged 5 commits into from
Nov 9, 2022

Conversation

klinki
Copy link
Contributor

@klinki klinki commented Oct 15, 2022

This PR fixes issue #25782 and allows to set [cdkMenuTriggerFor]='null'

@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label Oct 15, 2022
@klinki klinki force-pushed the feature/port-pr-24437-to-cdk branch from cb5afb4 to 365f3a9 Compare October 22, 2022 11:16
@klinki klinki marked this pull request as ready for review October 22, 2022 11:19
/** run change detection and, extract and set the rendered elements */
const detectChanges = () => {
fixture.detectChanges();
grabElementsForTesting();
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that you need to call this after each change detection. The element is going to stay the same after ngAfterContentInit.


@Component({
template: `
<button [cdkMenuTriggerFor]="null">First</button>
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that we need an entirely separate fixture where it is set to null. Instead we should adapt an existing fixture so we can also test that the DOM is updated on dynamic changes. See how it's done for MatMenu https://github.com/angular/components/blob/main/src/material/menu/menu.spec.ts#L92.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's good idea, I updated tests.

@klinki klinki force-pushed the feature/port-pr-24437-to-cdk branch from 365f3a9 to 4a77921 Compare November 4, 2022 19:53
Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

The change LGTM, but the CI is failing because:

  1. The commit title should start with feat(, not feature(.
  2. You should run yarn approve-api cdk/menu and commit the changed API golden file.

@@ -93,7 +93,13 @@ export class CdkMenuItem implements FocusableOption, FocusableElement, Toggler,
@Output('cdkMenuItemTriggered') readonly triggered: EventEmitter<void> = new EventEmitter();

/** Whether the menu item opens a menu. */
readonly hasMenu = !!this._menuTrigger;
get hasMenu() {
if (this._menuTrigger?.menuTemplateRef == null) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: this can be simplified to return this._menuTrigger?.menuTemplateRef != null.

@klinki klinki changed the title feature(cdk/menu): Allow setting cdkMenuTriggerFor null feat(cdk/menu): Allow setting cdkMenuTriggerFor null Nov 8, 2022
- Update hasMenu
- Add yarn approve-api cdk/menu
- Uncomment xdescribe and simplify it only for cdkMenuTrigger
@@ -1,3 +1,4 @@
import {CdkContextMenuTrigger} from './context-menu-trigger';
Copy link
Contributor

Choose a reason for hiding this comment

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

the linter is complaining that this import is unused

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

LGTM

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker target: minor This PR is targeted for the next minor release labels Nov 9, 2022
@crisbeto crisbeto merged commit e0a74b9 into angular:main Nov 9, 2022
@klinki klinki deleted the feature/port-pr-24437-to-cdk branch November 9, 2022 10:59
@angular-automatic-lock-bot
Copy link

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 Dec 10, 2022
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 detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants