Skip to content
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

md-list-item disabled property #763

Closed
theunreal opened this issue Jun 25, 2016 · 11 comments
Closed

md-list-item disabled property #763

theunreal opened this issue Jun 25, 2016 · 11 comments
Labels
feature This issue represents a new feature or feature request rather than a bug or bug fix P5 The team acknowledges the request but does not plan to address it, it remains open for discussion

Comments

@theunreal
Copy link

Bug, feature request, or proposal:

Proposal

What is the expected behavior?

Angular material2 list [disabled] item. An option to bind [disabled] to md-list-item in order to disable it (same as how the button disabled property works).

What is the current behavior?

no [disabled] property binding with md-list-item

What is the use-case or motivation for changing an existing behavior?

A list is not a button, but used for navigation and accessing data. [disabled] property can be very useful in such cases.

Which versions of Angular, Material, OS, browsers are affected?

All

@jelbourn jelbourn added the feature This issue represents a new feature or feature request rather than a bug or bug fix label Jun 27, 2016
@jelbourn
Copy link
Member

In general, disabled should live on the appropriate <button> / <a> elements, but it might make sense to have a style for disabled list items.

cc @kara

@jelbourn jelbourn added the P5 The team acknowledges the request but does not plan to address it, it remains open for discussion label Jun 27, 2016
@code-tree
Copy link
Contributor

This would be nice to have.

My use case: settings page, using md-list for settings, and some of which may be disabled.

@moneal
Copy link

moneal commented Aug 3, 2017

This makes a lot of sense to me. I have a md-nav-list and being able to disable some options depending on account settings seems appropriate. I think this would function the same as md-menu.

@angular angular deleted a comment from timmyrosen Sep 19, 2017
@mrburrito
Copy link

+1

I'm using md-nav-list as a menu and need to be able to disable some or all of the list based on application state. I tried using md-button as the list items, but it doesn't render properly.

@WaterBleu
Copy link

in #3624 says that not putting the list-item to be disabled, yet this is still open..
what is the status on this?

@angular angular deleted a comment from Maccodonaldo Jan 10, 2018
@mina-skunk
Copy link
Contributor

I understand that the native anchor element has no disabled attribute but its hard to follow why a[mat-button] and a[mat-menu-item] use disabled input but a[mat-list-item] does not.

@cmd-johnson
Copy link

My workaround for now is to handle this through CSS:

a[mat-list-item].disabled {
  opacity: 0.2;
  pointer-events: none;
}
<mat-nav-list>
  <a mat-list-item>Clickable</a>
  <a mat-list-item class="disabled">Disabled</a>
</mat-nav-list>

It's not the same as a disabled attribute, but good enough for my use case.

@jelbourn
Copy link
Member

Closing this since mat-action-list exists now which can have disable items

@mina-skunk
Copy link
Contributor

mina-skunk commented Nov 1, 2019

Even mat-action-list list doesn't seem to have disabled style

<mat-action-list>
  <button mat-list-item (click)="save()" disabled> Save </button>
  <button mat-list-item (click)="undo()"> Undo </button>
</mat-action-list>

image

I'm using this

@Directive({
  selector: 'button[mat-list-item]',
  host: {
    '[class.mat-list-item-disabled]': 'disabled',
    '[attr.aria-disabled]': 'disabled',
    '[attr.disabled]': 'disabled || null'
  },
  inputs: ['disabled']
})
export class ListItemDisabledButtonStylerDirective extends _ListItemDisabledStylerDirectiveMixinBase implements CanDisable { }

to add selection list's mat-list-item-disabled

image

and for mat-nav-list

@Directive({
  selector: 'mat-list-item, a[mat-list-item]',
  host: {
    '[class.mat-list-item-disabled]': 'disabled',
    '[attr.aria-disabled]': 'disabled'
  },
  inputs: ['disabled']
})
export class ListItemDisabledDirective extends _ListItemDisabledStylerDirectiveMixinBase implements CanDisable, OnChanges {

  constructor(
    @Optional() private matListItem?: MatListItem
  ) {
    super();
  }

  public ngOnChanges(changes: SimpleChanges): void {
    if (changes['disabled'] && this.matListItem) { // TODO matListItem null ?
      this.matListItem.disableRipple = this.disabled;
    }
  }

  @HostListener('click', ['$event'])
  public clickHandler(event: Event): boolean {
    if (this.disabled) {
      event.preventDefault();
      return false;
    }
    return true;
  }

}

https://stackblitz.com/edit/components-issue-th1faq-mat-list-item-disabled?file=app%2Flist-item-disabled-styler.directive.ts

@jelbourn
Copy link
Member

jelbourn commented Nov 1, 2019

@william-lohan good catch, I filed #17574

@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 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature This issue represents a new feature or feature request rather than a bug or bug fix P5 The team acknowledges the request but does not plan to address it, it remains open for discussion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants