Skip to content

Commit f027f38

Browse files
authored
fix(angular/core): make SbbOption generic (#1027)
Makes `SbbOption` generic so that consumers can type its `value` to something different from `any`. angular/components#20242
1 parent 388d3a6 commit f027f38

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/angular/core/option/option.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ import { SbbOptionParentComponent, SBB_OPTION_PARENT_COMPONENT } from './option-
3232
let uniqueIdCounter = 0;
3333

3434
/** Event object emitted by SbbOption when selected or deselected. */
35-
export class SbbOptionSelectionChange {
35+
export class SbbOptionSelectionChange<T = any> {
3636
constructor(
3737
/** Reference to the option that emitted the event. */
38-
public source: SbbOption,
38+
public source: SbbOption<T>,
3939
/** Whether the change in the option's value was a result of a user action. */
4040
public isUserInput = false
4141
) {}
@@ -61,7 +61,9 @@ export class SbbOptionSelectionChange {
6161
'[class.sbb-disabled]': 'disabled',
6262
},
6363
})
64-
export class SbbOption implements AfterViewChecked, OnDestroy, FocusableOption, Highlightable {
64+
export class SbbOption<T = any>
65+
implements AfterViewChecked, OnDestroy, FocusableOption, Highlightable
66+
{
6567
private _selected = false;
6668
private _active = false;
6769
private _disabled = false;
@@ -81,7 +83,7 @@ export class SbbOption implements AfterViewChecked, OnDestroy, FocusableOption,
8183
}
8284

8385
/** The form value of the option. */
84-
@Input() value: any;
86+
@Input() value: T;
8587

8688
/** The unique ID of the option. */
8789
@Input() id: string = `sbb-option-${uniqueIdCounter++}`;
@@ -98,7 +100,7 @@ export class SbbOption implements AfterViewChecked, OnDestroy, FocusableOption,
98100

99101
/** Event emitted when the option is selected or deselected. */
100102
// tslint:disable-next-line:no-output-on-prefix
101-
@Output() readonly onSelectionChange = new EventEmitter<SbbOptionSelectionChange>();
103+
@Output() readonly onSelectionChange = new EventEmitter<SbbOptionSelectionChange<T>>();
102104

103105
/** Emits when the state of the option changes and any parents have to be notified. */
104106
readonly _stateChanges = new Subject<void>();
@@ -341,7 +343,7 @@ export class SbbOption implements AfterViewChecked, OnDestroy, FocusableOption,
341343

342344
/** Emits the selection change event. */
343345
private _emitSelectionChangeEvent(isUserInput = false): void {
344-
this.onSelectionChange.emit(new SbbOptionSelectionChange(this, isUserInput));
346+
this.onSelectionChange.emit(new SbbOptionSelectionChange<T>(this, isUserInput));
345347
}
346348
}
347349

0 commit comments

Comments
 (0)