Skip to content

Commit b9e079c

Browse files
fix: update items input type to readonly in NgSelectComponent (ng-select#2704)
* feat: add Angular project cursor rules and guidelines for best practices - Introduced a comprehensive set of rules for Angular projects, covering topics such as using the latest Angular and TypeScript versions, modern features, component architecture, type safety, dependency injection, API communication, state management, testing, accessibility, and documentation. - Emphasized the use of Angular signals, standalone components, and strict typing to enhance code quality and maintainability. - Included guidelines for code generation to ensure consistency and adherence to best practices. * fix: clean up imports and improve code formatting in NgSelectComponent - Removed duplicate imports for contentChild, contentChildren, and computed. - Adjusted formatting for better readability in several areas, including promise handling and observable subscriptions. - Ensured consistent use of arrow function syntax and spacing throughout the component. * fix: converts items as input signal - Adjusted HTML formatting for better readability in the data source array example. - Cleaned up import statements in the data source array example component. - Updated test expectations in NgSelectComponent tests to reflect changes in item handling. * fix: refactor items input handling in NgSelectComponent * fix: update items input type to readonly in NgSelectComponent - Changed the items input type from mutable to readonly to enhance type safety and prevent unintended modifications. - Updated the private method _setItems to reflect the new readonly type for items. --------- Co-authored-by: Pavan Kumar Jadda <17564080+pavankjadda@users.noreply.github.com>
1 parent e54234a commit b9e079c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/ng-select/lib/ng-select.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export class NgSelectComponent implements OnDestroy, OnChanges, OnInit, AfterVie
158158
readonly bindValue = model<string>(undefined);
159159
readonly appearance = model<string>(undefined);
160160
readonly isOpen = model<boolean>(false);
161-
readonly items = input<any[]>([]);
161+
readonly items = input<readonly any[]>([]);
162162
// output events
163163
readonly blurEvent = output<any>({ alias: 'blur' });
164164
readonly focusEvent = output<any>({ alias: 'focus' });
@@ -723,7 +723,7 @@ export class NgSelectComponent implements OnDestroy, OnChanges, OnInit, AfterVie
723723
this.searchTerm = selected?.label ?? null;
724724
}
725725

726-
private _setItems(items: any[]) {
726+
private _setItems(items: readonly any[]) {
727727
const firstItem = items[0];
728728
this.bindLabel.set(this.bindLabel() || this._defaultLabel);
729729
this._primitive = isDefined(firstItem) ? !isObject(firstItem) : this._primitive || this.bindLabel() === this._defaultLabel;

0 commit comments

Comments
 (0)