Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/optimus-ui/src/autofocus/autofocus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ class TestAutofocusDynamicComponent {
autofocusEnabled = false;
}

@Component({
standalone: false,
selector: 'test-autofocus-undefined',
template: `<input type="text" [pAutoFocus]="autofocusEnabled" />`
})
class TestAutofocusUndefinedComponent {
autofocusEnabled: boolean | undefined = undefined;
}

@Component({
standalone: false,
selector: 'test-autofocus-button',
Expand Down Expand Up @@ -198,6 +207,7 @@ describe('AutoFocus', () => {
TestAutofocusDisabledComponent,
TestAutofocusEnabledComponent,
TestAutofocusDynamicComponent,
TestAutofocusUndefinedComponent,
TestAutofocusButtonComponent,
TestAutofocusDivComponent,
TestAutofocusMultipleElementsComponent,
Expand Down Expand Up @@ -298,6 +308,15 @@ describe('AutoFocus', () => {
await fixture.whenStable();
expect(element.hasAttribute('autofocus')).toBe(false);
});

it('should remove autofocus attribute when autofocus is undefined', async () => {
const undefinedFixture = TestBed.createComponent(TestAutofocusUndefinedComponent);
await undefinedFixture.whenStable();

const undefinedElement = undefinedFixture.debugElement.query(By.css('input')).nativeElement;

expect(undefinedElement.hasAttribute('autofocus')).toBe(false);
});
});

describe('Focus Behavior - Browser Platform', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/optimus-ui/src/autofocus/autofocus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class AutoFocus extends BaseComponent {

onAfterContentChecked() {
// This sets the `attr.autofocus` which is different than the Input `autofocus` attribute.
if (this.autofocus === false) {
if (!this.autofocus) {
this.host.nativeElement.removeAttribute('autofocus');
} else {
this.host.nativeElement.setAttribute('autofocus', true);
Expand Down
8 changes: 8 additions & 0 deletions packages/optimus-ui/src/button/button.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ describe('Button', () => {
expect(buttonInstance.autofocus).toBe(false);
});

it('should not set the autofocus attribute when autofocus is left unset', () => {
const standaloneFixture = TestBed.createComponent(Button);
standaloneFixture.detectChanges();

const standaloneButtonElement = standaloneFixture.debugElement.query(By.css('button')).nativeElement;
expect(standaloneButtonElement.hasAttribute('autofocus')).toBe(false);
});

it('should render with correct attributes', () => {
expect(buttonElement.tagName.toLowerCase()).toBe('button');
expect(buttonElement.type).toBe('button');
Expand Down
8 changes: 8 additions & 0 deletions packages/optimus-ui/src/datepicker/datepicker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,14 @@ describe('DatePicker', () => {
const inputElement = testFixture.debugElement.query(By.css('input'));
expect(inputElement.nativeElement.className).toContain('custom-input');
});

it('should not set the autofocus attribute when autofocus is left unset', async () => {
testFixture.changeDetectorRef.markForCheck();
await testFixture.whenStable();

const inputElement = testFixture.debugElement.query(By.css('input'));
expect(inputElement.nativeElement.hasAttribute('autofocus')).toBe(false);
});
});

describe('Event Handling', () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/optimus-ui/src/multiselect/multiselect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ describe('MultiSelect', () => {
expect(multiSelect).toBeTruthy();
});

it('should not set the autofocus attribute when autofocus is left unset', () => {
const focusInput = fixture.debugElement.query(By.css('input[role="combobox"]'));
expect(focusInput.nativeElement.hasAttribute('autofocus')).toBe(false);
});

it('should have default values', () => {
expect(multiSelect.filter).toBe(true);
expect(multiSelect.showToggleAll).toBe(true);
Expand All @@ -416,6 +421,7 @@ describe('MultiSelect', () => {
expect(multiSelect.lazy).toBe(false);
expect(multiSelect.loading).toBe(false);
expect(multiSelect.autofocusFilter).toBe(false);
expect(multiSelect.autofocus).toBeUndefined();
expect(multiSelect.display).toBe('comma');
expect(multiSelect.showClear).toBe(true);
expect(multiSelect.autoOptionFocus).toBe(false);
Expand Down
26 changes: 26 additions & 0 deletions packages/optimus-ui/src/radiobutton/radiobutton.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ class TestBasicRadioComponent {
}
}

// RadioButton with the autofocus input left unbound (default/undefined)
@Component({
standalone: true,
imports: [RadioButton, FormsModule],
template: ` <p-radiobutton name="test-unset-autofocus" value="option1" [(ngModel)]="selectedValue" /> `
})
class TestUnsetAutofocusRadioComponent {
selectedValue: any = null as any;
}

// Radio group test component
@Component({
standalone: true,
Expand Down Expand Up @@ -492,6 +502,22 @@ describe('RadioButton', () => {
});
});

describe('Autofocus Attribute Regression', () => {
it('should not set the autofocus attribute when autofocus is left unset', async () => {
await TestBed.configureTestingModule({
imports: [TestUnsetAutofocusRadioComponent],
providers: [provideZonelessChangeDetection()]
}).compileComponents();

const fixture = TestBed.createComponent(TestUnsetAutofocusRadioComponent);
fixture.detectChanges();
await fixture.whenStable();

const inputElement = fixture.debugElement.query(By.css('input[type="radio"]')).nativeElement;
expect(inputElement.hasAttribute('autofocus')).toBe(false);
});
});

describe('Binary Mode Tests', () => {
let component: TestBinaryRadioComponent;
let fixture: ComponentFixture<TestBinaryRadioComponent>;
Expand Down
22 changes: 22 additions & 0 deletions packages/optimus-ui/src/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ class TestBasicSelectComponent {
}
}

// Select with the autofocus input left unbound (default/undefined)
@Component({
standalone: false,
template: ` <p-select [options]="options" [(ngModel)]="selectedValue" optionLabel="name" optionValue="code"></p-select> `
})
class TestUnsetAutofocusSelectComponent {
options = [
{ name: 'Option 1', code: 'opt1' },
{ name: 'Option 2', code: 'opt2' }
];
selectedValue: any;
}

@Component({
standalone: false,
template: `
Expand Down Expand Up @@ -811,6 +824,7 @@ describe('Select', () => {
imports: [CommonModule, FormsModule, ReactiveFormsModule, Select],
declarations: [
TestBasicSelectComponent,
TestUnsetAutofocusSelectComponent,
TestReactiveFormSelectComponent,
TestGroupedSelectComponent,
TestSelectPTemplateComponent,
Expand All @@ -837,6 +851,14 @@ describe('Select', () => {
expect(selectInstance).toBeTruthy();
});

it('should not set the autofocus attribute when autofocus is left unset', () => {
const unsetFixture = TestBed.createComponent(TestUnsetAutofocusSelectComponent);
unsetFixture.detectChanges();

const focusElement = unsetFixture.debugElement.query(By.css('[role="combobox"]'));
expect(focusElement.nativeElement.hasAttribute('autofocus')).toBe(false);
});

it('should have default values', () => {
// Note: component uses bound values from TestBasicSelectComponent
expect(selectInstance.placeholder()).toBe('Select an option');
Expand Down
8 changes: 8 additions & 0 deletions packages/optimus-ui/src/slider/slider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ describe('Slider', () => {
expect(component.autofocus).toBe(true);
});

it('should not set the autofocus attribute on the handle when autofocus is left unset', async () => {
fixture.detectChanges();
await fixture.whenStable();

const handle = fixture.debugElement.query(By.css('[data-pc-section="handle"]'));
expect(handle.nativeElement.hasAttribute('autofocus')).toBe(false);
});

it('should initialize handle values array', () => {
expect(component.handleValues).toEqual([]);
expect(component.handleIndex).toBe(0);
Expand Down
9 changes: 9 additions & 0 deletions packages/optimus-ui/src/table/table.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,15 @@ describe('Table', () => {
const columnFilters = testFixture.debugElement.queryAll(By.css('p-columnFilter'));
expect(columnFilters.length).toBe(2);
});

it('should not set the autofocus attribute on column filter menu buttons', () => {
const filterButtons = testFixture.debugElement.queryAll(By.css('.p-datatable-column-filter-button'));
expect(filterButtons.length).toBeGreaterThan(0);

for (const filterButton of filterButtons) {
expect(filterButton.nativeElement.hasAttribute('autofocus')).toBe(false);
}
});
});

describe('Virtual Scroll Functionality', () => {
Expand Down
Loading
Loading