-
Notifications
You must be signed in to change notification settings - Fork 13.4k
fix(modal): allow sheet modals to skip focus trap #30689
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
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3c08630
test(modal): adding test for sheet modals that should help us prevent…
ShaneK 846b7cd
fix(modal): allow sheet modals to skip focus trap
ShaneK 69e5128
fix(lint): ran lint fix
ShaneK d0c4f0a
test(angular): adding link to new inline modal test
ShaneK 38179d5
tests(core): removing test that didn't do anything but broke automate…
ShaneK df354a7
Merge branch 'main' of github.com:ionic-team/ionic-framework into FW-…
ShaneK 3b1da5d
fix(sheet): disabling backdrop when focus trap is disabled
ShaneK 435d7e2
fix(overlay): fixing issues with teleported modals
ShaneK 03435a3
fix(lint): fixing lint
ShaneK bbe4154
test(angular): copying new lazy tests to standalone, fixing react rou…
ShaneK bbc80c8
test(react): fixing changed route in tests
ShaneK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/angular/test/base/e2e/src/lazy/modal-dynamic-wrapper.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
test.describe('Modals: Dynamic Wrapper', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto('/lazy/modal-dynamic-wrapper'); | ||
}); | ||
|
||
test('should render dynamic component inside modal', async ({ page }) => { | ||
await page.locator('#open-dynamic-modal').click(); | ||
|
||
await expect(page.locator('ion-modal')).toBeVisible(); | ||
await expect(page.locator('#dynamic-component-loaded')).toBeVisible(); | ||
}); | ||
|
||
test('should allow interacting with background content while sheet is open', async ({ page }) => { | ||
await page.locator('#open-dynamic-modal').click(); | ||
|
||
await expect(page.locator('ion-modal')).toBeVisible(); | ||
|
||
await page.locator('#background-action').click(); | ||
|
||
await expect(page.locator('#background-action-count')).toHaveText('1'); | ||
}); | ||
|
||
test('should prevent interacting with background content when focus is trapped', async ({ page }) => { | ||
await page.locator('#open-focused-modal').click(); | ||
|
||
await expect(page.locator('ion-modal')).toBeVisible(); | ||
|
||
// Attempt to click the background button via coordinates; click should be intercepted by backdrop | ||
const box = await page.locator('#background-action').boundingBox(); | ||
if (box) { | ||
await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2); | ||
} | ||
|
||
await expect(page.locator('#background-action-count')).toHaveText('0'); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
packages/angular/test/base/e2e/src/lazy/modal-sheet-inline.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
test.describe('Modals: Inline Sheet', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto('/lazy/modal-sheet-inline'); | ||
}); | ||
|
||
test('should open inline sheet modal', async ({ page }) => { | ||
await page.locator('#present-inline-sheet-modal').click(); | ||
|
||
await expect(page.locator('ion-modal')).toBeVisible(); | ||
await expect(page.locator('#current-breakpoint')).toHaveText('0.2'); | ||
await expect(page.locator('ion-modal ion-item')).toHaveCount(4); | ||
}); | ||
|
||
test('should expand to 0.75 breakpoint when searchbar is clicked', async ({ page }) => { | ||
await page.locator('#present-inline-sheet-modal').click(); | ||
await expect(page.locator('#current-breakpoint')).toHaveText('0.2'); | ||
|
||
await page.locator('ion-modal ion-searchbar').click(); | ||
|
||
await expect(page.locator('#current-breakpoint')).toHaveText('0.75'); | ||
}); | ||
|
||
test('should allow interacting with background content while sheet is open', async ({ page }) => { | ||
await page.locator('#present-inline-sheet-modal').click(); | ||
|
||
await expect(page.locator('ion-modal')).toBeVisible(); | ||
|
||
await page.locator('#background-action').click(); | ||
|
||
await expect(page.locator('#background-action-count')).toHaveText('1'); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
packages/angular/test/base/e2e/src/standalone/modal-dynamic-wrapper.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
test.describe('Modals: Dynamic Wrapper (standalone)', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto('/standalone/modal-dynamic-wrapper'); | ||
}); | ||
|
||
test('should render dynamic component inside modal', async ({ page }) => { | ||
await page.locator('#open-dynamic-modal').click(); | ||
|
||
await expect(page.locator('ion-modal')).toBeVisible(); | ||
await expect(page.locator('#dynamic-component-loaded')).toBeVisible(); | ||
}); | ||
|
||
test('should allow interacting with background content while sheet is open', async ({ page }) => { | ||
await page.locator('#open-dynamic-modal').click(); | ||
|
||
await expect(page.locator('ion-modal')).toBeVisible(); | ||
|
||
await page.locator('#background-action').click(); | ||
|
||
await expect(page.locator('#background-action-count')).toHaveText('1'); | ||
}); | ||
|
||
test('should prevent interacting with background content when focus is trapped', async ({ page }) => { | ||
await page.locator('#open-focused-modal').click(); | ||
|
||
await expect(page.locator('ion-modal')).toBeVisible(); | ||
|
||
// Attempt to click the background button via coordinates; click should be intercepted by backdrop | ||
const box = await page.locator('#background-action').boundingBox(); | ||
if (box) { | ||
await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2); | ||
} | ||
|
||
await expect(page.locator('#background-action-count')).toHaveText('0'); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
packages/angular/test/base/e2e/src/standalone/modal-sheet-inline.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
test.describe('Modals: Inline Sheet (standalone)', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto('/standalone/modal-sheet-inline'); | ||
}); | ||
|
||
test('should open inline sheet modal', async ({ page }) => { | ||
await page.locator('#present-inline-sheet-modal').click(); | ||
|
||
await expect(page.locator('ion-modal')).toBeVisible(); | ||
await expect(page.locator('#current-breakpoint')).toHaveText('0.2'); | ||
await expect(page.locator('ion-modal ion-item')).toHaveCount(4); | ||
}); | ||
|
||
test('should expand to 0.75 breakpoint when searchbar is clicked', async ({ page }) => { | ||
await page.locator('#present-inline-sheet-modal').click(); | ||
await expect(page.locator('#current-breakpoint')).toHaveText('0.2'); | ||
|
||
await page.locator('ion-modal ion-searchbar').click(); | ||
|
||
await expect(page.locator('#current-breakpoint')).toHaveText('0.75'); | ||
}); | ||
|
||
test('should allow interacting with background content while sheet is open', async ({ page }) => { | ||
await page.locator('#present-inline-sheet-modal').click(); | ||
|
||
await expect(page.locator('ion-modal')).toBeVisible(); | ||
|
||
await page.locator('#background-action').click(); | ||
|
||
await expect(page.locator('#background-action-count')).toHaveText('1'); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...gular/test/base/src/app/lazy/modal-dynamic-wrapper/dynamic-component-wrapper.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Component, ComponentRef, Input, OnDestroy, OnInit, ViewChild, ViewContainerRef } from "@angular/core"; | ||
|
||
@Component({ | ||
selector: 'app-dynamic-component-wrapper', | ||
template: ` | ||
<ion-content> | ||
<ng-container #container></ng-container> | ||
</ion-content> | ||
`, | ||
standalone: false | ||
}) | ||
export class DynamicComponentWrapperComponent implements OnInit, OnDestroy { | ||
|
||
@Input() componentRef?: ComponentRef<unknown>; | ||
@ViewChild('container', { read: ViewContainerRef, static: true }) container!: ViewContainerRef; | ||
|
||
ngOnInit(): void { | ||
if (this.componentRef) { | ||
this.container.insert(this.componentRef.hostView); | ||
} | ||
} | ||
|
||
ngOnDestroy(): void { | ||
this.componentRef?.destroy(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...s/angular/test/base/src/app/lazy/modal-dynamic-wrapper/dynamic-modal-content.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Component, EventEmitter, Output } from "@angular/core"; | ||
|
||
@Component({ | ||
selector: 'app-dynamic-modal-content', | ||
template: ` | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Dynamic Sheet Content</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<p id="dynamic-component-loaded">Dynamic component rendered inside wrapper.</p> | ||
<ion-button id="dismiss-dynamic-modal" (click)="dismiss.emit()">Close</ion-button> | ||
</ion-content> | ||
`, | ||
standalone: false | ||
}) | ||
export class DynamicModalContentComponent { | ||
@Output() dismiss = new EventEmitter<void>(); | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/angular/test/base/src/app/lazy/modal-dynamic-wrapper/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './modal-dynamic-wrapper.component'; | ||
export * from './modal-dynamic-wrapper.module'; |
16 changes: 16 additions & 0 deletions
16
...ular/test/base/src/app/lazy/modal-dynamic-wrapper/modal-dynamic-wrapper-routing.module.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { NgModule } from "@angular/core"; | ||
import { RouterModule } from "@angular/router"; | ||
import { ModalDynamicWrapperComponent } from "."; | ||
|
||
@NgModule({ | ||
imports: [ | ||
RouterModule.forChild([ | ||
{ | ||
path: '', | ||
component: ModalDynamicWrapperComponent | ||
} | ||
]) | ||
], | ||
exports: [RouterModule] | ||
}) | ||
export class ModalDynamicWrapperRoutingModule { } |
8 changes: 8 additions & 0 deletions
8
...angular/test/base/src/app/lazy/modal-dynamic-wrapper/modal-dynamic-wrapper.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<ion-button id="open-dynamic-modal" (click)="openModal()">Open Dynamic Sheet Modal</ion-button> | ||
<ion-button id="open-focused-modal" color="primary" (click)="openFocusedModal()">Open Focus-Trapped Sheet Modal</ion-button> | ||
<ion-button id="background-action" (click)="onBackgroundActionClick()">Background Action</ion-button> | ||
<p> | ||
Background action count: <span id="background-action-count">{{ backgroundActionCount }}</span> | ||
</p> | ||
|
||
<ng-template #modalHost></ng-template> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.