Skip to content
2 changes: 1 addition & 1 deletion eslint-baseline.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"root": 1059,
"root": 924,
"test-app": 0
}
2 changes: 1 addition & 1 deletion src/formly/components/autocomplete/test.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
export class TestAutocompleteService implements AutocompleteService {
public setFetchMethod() {}

public fetch(val: string): Observable<any> {
public fetch(val: string): Observable<unknown> {

Check warning on line 10 in src/formly/components/autocomplete/test.service.ts

View workflow job for this annotation

GitHub Actions / lint

'val' is defined but never used
return of([
{ key: "MD", value: "Maryland", category: "Places" },
{ key: "VA", value: "Virginia", category: "Places" },
Expand Down
31 changes: 24 additions & 7 deletions src/formly/sam-formly.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
import { ChangeDetectorRef, Component, OnInit } from "@angular/core";
import { FieldType } from "@ngx-formly/core";
import { FormControl } from "@angular/forms";

export interface SamFormlyTemplateComponent {
control?: FormControl;
}

@Component({
template: "",
standalone: false,
})
export abstract class AbstractSamFormly extends FieldType implements OnInit {
export abstract class AbstractSamFormly<
T extends SamFormlyTemplateComponent = SamFormlyTemplateComponent,
>
extends FieldType
implements OnInit
{
public cdr: ChangeDetectorRef;
public template: any;
public template: T;

public ngOnInit() {
this.setProperties(this.template, (<any>this).field.templateOptions);
this.setProperties(
this.template,
this.field.templateOptions as Record<string, unknown>
);
}

public setProperties(component: any, configuration: any) {
public setProperties(
component: T,
configuration: Record<string, unknown>
): void {
Object.keys(configuration).forEach((key) => {
component[key] = configuration[key];
(component as unknown as Record<string, unknown>)[key] =
configuration[key];
});
if ((<any>this).template.control) {
(<any>this).template.control = (<any>this).formControl;
if (this.template.control) {
this.template.control = this.formControl as FormControl;
}
this.cdr.detectChanges();
}
Expand Down
12 changes: 9 additions & 3 deletions src/ui-kit/directives/click-outside/click-outside.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { TestBed, waitForAsync, fakeAsync, tick } from "@angular/core/testing";
import {
TestBed,
waitForAsync,
fakeAsync,
tick,
ComponentFixture,
} from "@angular/core/testing";
import { Component, Output, ViewChild, EventEmitter } from "@angular/core";
import { By } from "@angular/platform-browser";

Expand All @@ -16,7 +22,7 @@ import { SamClickOutsideDirective } from "./click-outside.directive";
standalone: false,
})
class TestComponent {
@Output() action: EventEmitter<any> = new EventEmitter<any>();
@Output() action: EventEmitter<boolean> = new EventEmitter<boolean>();
@ViewChild("var", { static: true }) var;
clickOutsideHandler() {
this.action.emit(true);
Expand All @@ -25,7 +31,7 @@ class TestComponent {
describe("The Sam Click Outside directive", () => {
let directive: SamClickOutsideDirective;
let component: TestComponent;
let fixture: any;
let fixture: ComponentFixture<TestComponent>;

beforeEach(() => {
TestBed.configureTestingModule({
Expand Down
4 changes: 2 additions & 2 deletions src/ui-kit/directives/drag-drop/drag-drop.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestBed } from "@angular/core/testing";
import { TestBed, ComponentFixture } from "@angular/core/testing";

import { Component, Output, ViewChild, EventEmitter } from "@angular/core";
import { By } from "@angular/platform-browser";
Expand Down Expand Up @@ -41,7 +41,7 @@ class TestComponent {
describe("The Sam Focus directive", () => {
let directive: SamDragDropDirective;
let component: TestComponent;
let fixture: any;
let fixture: ComponentFixture<TestComponent>;

beforeEach(() => {
TestBed.configureTestingModule({
Expand Down
12 changes: 9 additions & 3 deletions src/ui-kit/directives/focus/focus.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { TestBed, waitForAsync, fakeAsync, tick } from "@angular/core/testing";
import {
TestBed,
waitForAsync,
fakeAsync,
tick,
ComponentFixture,
} from "@angular/core/testing";

import { Component, Output, ViewChild, EventEmitter } from "@angular/core";
import { By } from "@angular/platform-browser";
Expand All @@ -17,7 +23,7 @@ import { SamFocusDirective } from "./focus.directive";
standalone: false,
})
class TestComponent {
@Output() action: EventEmitter<any> = new EventEmitter<any>();
@Output() action: EventEmitter<boolean> = new EventEmitter<boolean>();
@ViewChild("var", { static: true }) var;
focusHandler() {
this.action.emit(true);
Expand All @@ -26,7 +32,7 @@ class TestComponent {
describe("The Sam Focus directive", () => {
let directive: SamFocusDirective;
let component: TestComponent;
let fixture: any;
let fixture: ComponentFixture<TestComponent>;

beforeEach(() => {
TestBed.configureTestingModule({
Expand Down
43 changes: 27 additions & 16 deletions src/ui-kit/directives/sticky/sticky.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import {
/**
* The sam-sticky directive is made to help nav bar stick on the page
*/
export interface OffsetParentLike {
offsetTop: number;
offsetParent: Element | null;
}

@Directive({
selector: "[sam-sticky]",
standalone: false,
Expand All @@ -35,7 +40,7 @@ export class SamStickyComponent implements OnInit, AfterViewChecked {
private elemWidth: number;

@HostListener("window:resize", ["$event"])
resize(event) {
resize(event: Event): void {
// Set element to initial styles
// to help finding the initial element width
this.el.nativeElement.style.position = "static";
Expand All @@ -46,7 +51,7 @@ export class SamStickyComponent implements OnInit, AfterViewChecked {
}

@HostListener("window:scroll", ["$event"])
scroll(event) {
scroll(event: Event): void {
this.makeSticky();
}

Expand Down Expand Up @@ -99,50 +104,56 @@ export class SamStickyComponent implements OnInit, AfterViewChecked {
/**
* Get the distance from the element to the top of the document
*/
getElemDistanceToTop(elem) {
getElemDistanceToTop(elem: OffsetParentLike): number {
let distance = 0;
let el = elem;
let el: OffsetParentLike = elem;
if (el.offsetParent) {
do {
distance += el.offsetTop;
el = el.offsetParent;
el = el.offsetParent as unknown as OffsetParentLike;
} while (el);
}
return distance;
}

isTallestAmongSiblings(): boolean {
let highest = true;
const parentContainer: any = document.getElementsByClassName(
const parentContainer = document.getElementsByClassName(
this.container
);
) as HTMLCollectionOf<HTMLElement>;
if (!parentContainer[0]) {
return highest;
}
const directChild = this.findDirectChild();
if (!directChild) {
return highest;
}
const height = directChild.offsetHeight;
Comment thread
fpigeonjr marked this conversation as resolved.

for (let i = 0; i < parentContainer[0].children.length; i++) {
if (
directChild !== parentContainer[0].children[i] &&
parentContainer[0].children[i].offsetHeight > height
(parentContainer[0].children[i] as HTMLElement).offsetHeight > height
) {
highest = false;
}
}
return highest;
}

findDirectChild() {
const parentContainer: any = document.getElementsByClassName(
findDirectChild(): HTMLElement | undefined {
const parentContainer = document.getElementsByClassName(
this.container
);
let directChild;
let curNode = this.el.nativeElement;
) as HTMLCollectionOf<HTMLElement>;
let directChild: HTMLElement | undefined;
let curNode: HTMLElement = this.el.nativeElement;
if (curNode.parentNode) {
do {
if (curNode.parentNode === parentContainer[0]) {
directChild = curNode;
break;
}
curNode = curNode.parentNode;
curNode = curNode.parentNode as HTMLElement;
} while (curNode);
}
return directChild;
Expand All @@ -155,9 +166,9 @@ export class SamStickyComponent implements OnInit, AfterViewChecked {
}
const defaultTopMargin = 20;
const defaultOffset = 50;
const parentContainer: any = document.getElementsByClassName(
const parentContainer = document.getElementsByClassName(
this.container
);
) as HTMLCollectionOf<HTMLElement>;
const documentHeight = this.getDocHeight();
const scrollPosition = this.getScrollTop() + window.innerHeight;
const parentContainerLimit =
Expand Down
25 changes: 17 additions & 8 deletions src/ui-kit/directives/sticky/sticky.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { TestBed, waitForAsync, fakeAsync, tick } from "@angular/core/testing";
import {
TestBed,
waitForAsync,
fakeAsync,
tick,
ComponentFixture,
} from "@angular/core/testing";

import { Component, ViewChild } from "@angular/core";
import { By } from "@angular/platform-browser";

// Load the implementations that should be tested
import { SamStickyComponent } from "./sticky.component";
import { SamStickyComponent, OffsetParentLike } from "./sticky.component";

@Component({
selector: "test-cmp",
Expand Down Expand Up @@ -33,7 +39,7 @@ class TestComponent {
describe("The Sam Sticky directive", () => {
let directive: SamStickyComponent;
let component: TestComponent;
let fixture: any;
let fixture: ComponentFixture<TestComponent>;

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -57,7 +63,7 @@ describe("The Sam Sticky directive", () => {
});

it("should handle when resized", () => {
directive.resize({});
directive.resize(new Event("resize"));
const comp = fixture.debugElement.query(By.css(".test-comp"));
fixture.detectChanges();
expect(comp.nativeElement.getAttribute("style")).toContain(
Expand All @@ -71,7 +77,7 @@ describe("The Sam Sticky directive", () => {
window.dispatchEvent(new Event("scroll"));
fixture.detectChanges();
expect(directive.scroll).toHaveBeenCalled();
directive.scroll(undefined);
directive.scroll(new Event("scroll"));
directive.makeSticky();

directive.limit = expectedLimit;
Expand All @@ -80,7 +86,7 @@ describe("The Sam Sticky directive", () => {

it("resize() recalculates elemWidth and calls makeSticky", () => {
const makeStickySpy = vi.spyOn(directive, "makeSticky");
directive.resize({});
directive.resize(new Event("resize"));
expect(makeStickySpy).toHaveBeenCalled();

const comp = fixture.debugElement.query(By.css(".test-comp"));
Expand Down Expand Up @@ -155,8 +161,11 @@ describe("The Sam Sticky directive", () => {
).nativeElement;
expect(directive.getElemDistanceToTop(nativeElement)).toBe(0);

const fakeParent = { offsetTop: 40, offsetParent: null };
const fakeElem = { offsetTop: 10, offsetParent: fakeParent };
const fakeParent: OffsetParentLike = { offsetTop: 40, offsetParent: null };
const fakeElem: OffsetParentLike = {
offsetTop: 10,
offsetParent: fakeParent as unknown as Element,
};
expect(directive.getElemDistanceToTop(fakeElem)).toBe(50);
});

Expand Down
7 changes: 4 additions & 3 deletions src/ui-kit/directives/tab-outside/taboutside.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ export class SamTabOutsideDirective {
/**
* Emitter for tabOutside event
*/
@Output() tabOutside: EventEmitter<any> = new EventEmitter();
@Output() tabOutside: EventEmitter<void> = new EventEmitter();

constructor(private _elementRef: ElementRef) {}

@HostListener("document:keyup", ["$event.target"])
public hasFocusChanged(target) {
const isInsideHost = this._elementRef.nativeElement.contains(target);
public hasFocusChanged(target: EventTarget | null): void {
const isInsideHost =
target instanceof Node && this._elementRef.nativeElement.contains(target);
if (!isInsideHost) {
this.tabOutside.emit(undefined);
}
Expand Down
12 changes: 9 additions & 3 deletions src/ui-kit/directives/tab-outside/taboutside.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { TestBed, waitForAsync, fakeAsync, tick } from "@angular/core/testing";
import {
TestBed,
waitForAsync,
fakeAsync,
tick,
ComponentFixture,
} from "@angular/core/testing";

import { Component, Output, ViewChild, EventEmitter } from "@angular/core";
import { By } from "@angular/platform-browser";
Expand All @@ -15,7 +21,7 @@ import { SamTabOutsideDirective } from "./taboutside.directive";
standalone: false,
})
class TestComponent {
@Output() action: EventEmitter<any> = new EventEmitter<any>();
@Output() action: EventEmitter<boolean> = new EventEmitter<boolean>();
@ViewChild("var", { static: true }) var;
tabOutsideHandler() {
this.action.emit(true);
Expand All @@ -24,7 +30,7 @@ class TestComponent {
describe("The Sam Tab Outside directive", () => {
let directive: SamTabOutsideDirective;
let component: TestComponent;
let fixture: any;
let fixture: ComponentFixture<TestComponent>;

beforeEach(() => {
TestBed.configureTestingModule({
Expand Down
6 changes: 3 additions & 3 deletions src/ui-kit/elements/button/button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class SamButtonComponent {
/**
* Emmits event on click
*/
@Output() onClick: EventEmitter<any> = new EventEmitter();
@Output() onClick: EventEmitter<Event> = new EventEmitter<Event>();

/**
* Sets the id that will assign to the button element (Deprecated)
Expand Down Expand Up @@ -110,7 +110,7 @@ export class SamButtonComponent {
*/
@Input() buttonClass: string = "";

private btnClassMap: any = {
private btnClassMap: Record<string, string> = {
// Types
default: "primary",
primary: "primary",
Expand Down Expand Up @@ -178,7 +178,7 @@ export class SamButtonComponent {
deprecator.render(this);
}

click($event) {
click($event: Event) {
if (!this.isDisabled) {
this.onClick.emit($event);
}
Expand Down
Loading
Loading