Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dialog): dialog gets focus when is opened - 7.1.x #3279

Merged
merged 22 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
21057b8
test(dialog): add test for focused dialog when opened #3199
Dec 3, 2018
c6788f2
fix(dialog): focus dialog on open #3199
Dec 3, 2018
7263358
Merge branch 'master' into tzhelev/fix-3199-7.1.x
tachojelev Dec 3, 2018
9315e07
Merge branch 'master' into tzhelev/fix-3199-7.1.x
tachojelev Dec 4, 2018
649236c
Merge branch 'master' into tzhelev/fix-3199-7.1.x
tachojelev Dec 4, 2018
d6fd59f
Merge branch 'master' into tzhelev/fix-3199-7.1.x
rkaraivanov Dec 4, 2018
fb92e32
Merge branch 'master' into tzhelev/fix-3199-7.1.x
tachojelev Dec 6, 2018
1db99ec
Merge branch 'tzhelev/fix-3199-6.2.x' of https://github.com/IgniteUI/…
Dec 6, 2018
078de59
Merge branch 'master' into tzhelev/fix-3199-7.1.x
tachojelev Dec 6, 2018
ec14378
chore(dialog): make lint happy #3199
Dec 6, 2018
6342d15
Merge branch 'master' into tzhelev/fix-3199-7.1.x
tachojelev Dec 6, 2018
59b7dc5
fix(focus): import focus module in focus spec #3199
Dec 6, 2018
652a8d4
Merge branch 'master' into tzhelev/fix-3199-7.1.x
tachojelev Dec 6, 2018
84c96e9
Merge branch 'master' into tzhelev/fix-3199-7.1.x
kdinev Dec 7, 2018
8d6c9ab
Merge branch 'master' into tzhelev/fix-3199-7.1.x
tachojelev Dec 7, 2018
e60f040
Merge branch 'master' into tzhelev/fix-3199-7.1.x
kdinev Dec 7, 2018
07ee203
Merge branch 'master' into tzhelev/fix-3199-7.1.x
kdinev Dec 7, 2018
c4e0468
Merge branch 'master' into tzhelev/fix-3199-7.1.x
tachojelev Dec 9, 2018
feb4d0c
Merge branch 'master' into tzhelev/fix-3199-7.1.x
tachojelev Dec 10, 2018
253e702
Merge branch 'master' into tzhelev/fix-3199-7.1.x
tachojelev Dec 10, 2018
6459830
Merge branch 'master' into tzhelev/fix-3199-7.1.x
tachojelev Dec 10, 2018
9bbf1b0
Merge branch 'master' into tzhelev/fix-3199-7.1.x
tachojelev Dec 11, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
<ng-content *ngIf="!message"></ng-content>

<div *ngIf="leftButtonLabel || rightButtonLabel" class="igx-dialog__window-actions">
<button *ngIf="leftButtonLabel" type="button" igxButton="{{ leftButtonType }}" igxButtonColor="{{ leftButtonColor }}" igxButtonBackground="{{ leftButtonBackgroundColor }}"
<button *ngIf="leftButtonLabel" type="button" [igxFocus]="isOpen" igxButton="{{ leftButtonType }}" igxButtonColor="{{ leftButtonColor }}" igxButtonBackground="{{ leftButtonBackgroundColor }}"
igxRipple="{{ leftButtonRipple }}" (click)="onInternalLeftButtonSelect($event)">
{{ leftButtonLabel }}
</button>
<button *ngIf="rightButtonLabel" type="button" igxButton="{{ rightButtonType }}" igxButtonColor="{{ rightButtonColor }}" igxButtonBackground="{{ rightButtonBackgroundColor }}"
<button *ngIf="rightButtonLabel" type="button" [igxFocus]="isOpen" igxButton="{{ rightButtonType }}" igxButtonColor="{{ rightButtonColor }}" igxButtonBackground="{{ rightButtonBackgroundColor }}"
igxRipple="{{ rightButtonRipple }}" (click)="onInternalRightButtonSelect($event)">
{{ rightButtonLabel }}
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, DebugElement, ElementRef, ViewChild } from '@angular/core';
import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations';
import { UIInteractions } from '../test-utils/ui-interactions.spec';
import { UIInteractions, wait } from '../test-utils/ui-interactions.spec';
import { IDialogEventArgs, IgxDialogComponent, IgxDialogModule } from './dialog.component';
import { configureTestSuite } from '../test-utils/configure-suite';

Expand Down Expand Up @@ -297,6 +297,31 @@ describe('Dialog', () => {
expect(overlayWrapper.classList.contains(OVERLAY_WRAPPER_CLASS)).toBe(false);
}));

it('Default button of the dialog is focused after opening the dialog and can be closed with keyboard.', (async() => {
const fix = TestBed.createComponent(DialogComponent);
fix.detectChanges();

const dialog: IgxDialogComponent = fix.componentInstance.dialog as IgxDialogComponent;
dialog.open();
fix.detectChanges();
await wait(16);

// Verify dialog is opened and its default right button is focused
const dialogDOM = fix.debugElement.query(By.css('.igx-dialog'));
const rightButton = dialogDOM.queryAll(By.css('button')).filter((b) => b.nativeElement.innerText === 'right button')[0];
expect(document.activeElement).toBe(rightButton.nativeElement);
expect(dialog.isOpen).toEqual(true);

// Press 'escape' key
UIInteractions.simulateKeyDownEvent(document.activeElement, 'Escape');
fix.detectChanges();
await wait(16);

// Verify dialog is closed and its default right button is no longer focused
expect(document.activeElement).not.toBe(rightButton.nativeElement);
expect(dialog.isOpen).toEqual(false);
}));

function dispatchEvent(element: HTMLElement, eventType: string) {
const event = new Event(eventType);
element.dispatchEvent(event);
Expand Down
3 changes: 2 additions & 1 deletion projects/igniteui-angular/src/lib/dialog/dialog.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { IgxDialogActionsDirective, IgxDialogTitleDirective } from './dialog.dir
import { IgxToggleModule, IgxToggleDirective } from '../directives/toggle/toggle.directive';
import { OverlaySettings, GlobalPositionStrategy, NoOpScrollStrategy, PositionSettings } from '../services';
import { slideInBottom, slideOutTop } from '../animations/slide/index';
import { IgxFocusModule } from '../directives/focus/focus.directive';

let DIALOG_ID = 0;
/**
Expand Down Expand Up @@ -485,6 +486,6 @@ export interface IDialogEventArgs {
@NgModule({
declarations: [IgxDialogComponent, IgxDialogTitleDirective, IgxDialogActionsDirective],
exports: [IgxDialogComponent, IgxDialogTitleDirective, IgxDialogActionsDirective],
imports: [CommonModule, IgxToggleModule, IgxButtonModule, IgxRippleModule]
imports: [CommonModule, IgxToggleModule, IgxButtonModule, IgxRippleModule, IgxFocusModule]
})
export class IgxDialogModule { }
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
tick
} from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { IgxFocusDirective } from './focus.directive';
import { IgxFocusDirective, IgxFocusModule } from './focus.directive';

import { configureTestSuite } from '../../test-utils/configure-suite';
import { EditorProvider } from '../../core/edit-provider';
Expand All @@ -19,13 +19,12 @@ describe('igxFocus', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
IgxFocusDirective,
SetFocusComponent,
NoFocusComponent,
TriggerFocusOnClickComponent,
CheckboxPickerComponent
],
imports: [ IgxCheckboxModule, IgxDatePickerModule, NoopAnimationsModule ]
imports: [ IgxFocusModule, IgxCheckboxModule, IgxDatePickerModule, NoopAnimationsModule ]
}).compileComponents();
}));

Expand Down