Skip to content

Commit

Permalink
refactor(material/core): allow option parent's disableRipple to be a …
Browse files Browse the repository at this point in the history
…signal

Expands the `MatOptionParentComponent` to allow the `disableRipple` to be a signal. This will be relevant in the time picker.
  • Loading branch information
crisbeto committed Sep 30, 2024
1 parent 54ae0b2 commit 030cdd6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/material/core/option/option-parent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* found in the LICENSE file at https://angular.dev/license
*/

import {InjectionToken} from '@angular/core';
import {InjectionToken, Signal} from '@angular/core';

/**
* Describes a parent component that manages a list of options.
* Contains properties that the options can inherit.
* @docs-private
*/
export interface MatOptionParentComponent {
disableRipple?: boolean;
disableRipple?: boolean | Signal<boolean>;
multiple?: boolean;
inertGroups?: boolean;
hideSingleSelectionIndicator?: boolean;
Expand Down
11 changes: 9 additions & 2 deletions src/material/core/option/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
ViewChild,
booleanAttribute,
inject,
isSignal,
Signal,
} from '@angular/core';
import {Subject} from 'rxjs';
import {MAT_OPTGROUP, MatOptgroup} from './optgroup';
Expand Down Expand Up @@ -87,6 +89,7 @@ export class MatOption<T = any> implements FocusableOption, AfterViewChecked, On
private _parent = inject<MatOptionParentComponent>(MAT_OPTION_PARENT_COMPONENT, {optional: true});
group = inject<MatOptgroup>(MAT_OPTGROUP, {optional: true});

private _signalDisableRipple = false;
private _selected = false;
private _active = false;
private _disabled = false;
Expand Down Expand Up @@ -119,7 +122,9 @@ export class MatOption<T = any> implements FocusableOption, AfterViewChecked, On

/** Whether ripples for the option are disabled. */
get disableRipple(): boolean {
return !!(this._parent && this._parent.disableRipple);
return this._signalDisableRipple
? (this._parent!.disableRipple as Signal<boolean>)()
: !!this._parent?.disableRipple;
}

/** Whether to display checkmark for single-selection. */
Expand All @@ -138,7 +143,9 @@ export class MatOption<T = any> implements FocusableOption, AfterViewChecked, On
readonly _stateChanges = new Subject<void>();

constructor(...args: unknown[]);
constructor() {}
constructor() {
this._signalDisableRipple = !!this._parent && isSignal(this._parent.disableRipple);
}

/**
* Whether or not the option is currently active and ready to be selected.
Expand Down
3 changes: 2 additions & 1 deletion tools/public_api_guard/material/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { OnInit } from '@angular/core';
import { Platform } from '@angular/cdk/platform';
import { Provider } from '@angular/core';
import { QueryList } from '@angular/core';
import { Signal } from '@angular/core';
import { Subject } from 'rxjs';
import { Version } from '@angular/core';

Expand Down Expand Up @@ -295,7 +296,7 @@ export class MatOptionModule {
// @public
export interface MatOptionParentComponent {
// (undocumented)
disableRipple?: boolean;
disableRipple?: boolean | Signal<boolean>;
// (undocumented)
hideSingleSelectionIndicator?: boolean;
// (undocumented)
Expand Down

0 comments on commit 030cdd6

Please sign in to comment.