Skip to content

Commit

Permalink
Merge pull request #772 from magiclabs/hcote-visibility-update
Browse files Browse the repository at this point in the history
change display css to visibility
  • Loading branch information
hcote authored Aug 9, 2024
2 parents 8f347f7 + b219f3d commit a573e0d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 60 deletions.
7 changes: 4 additions & 3 deletions packages/magic-sdk/src/iframe-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { ViewController, createDuplicateIframeWarning, createURL, createModalNot
* to render above all other DOM content.
*/
const overlayStyles: Partial<CSSStyleDeclaration> = {
display: 'none',
display: 'block',
visibility: 'hidden',
position: 'fixed',
top: '0',
right: '0',
Expand Down Expand Up @@ -98,14 +99,14 @@ export class IframeController extends ViewController {

protected async showOverlay() {
const iframe = await this.iframe;
iframe.style.display = 'block';
iframe.style.visibility = 'visible';
this.activeElement = document.activeElement;
iframe.focus();
}

protected async hideOverlay() {
const iframe = await this.iframe;
iframe.style.display = 'none';
iframe.style.visibility = 'hidden';
if (this.activeElement?.focus) this.activeElement.focus();
this.activeElement = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ beforeEach(() => {
browserEnv.stub('console.log', jest.fn());
});

test('Change display style to `none`', async () => {
test('Change visibility style to `hidden`', async () => {
(IframeController.prototype as any).init = function () {
this.iframe = {
style: { display: 'block' },
style: { visibility: 'hidden' },
};

return Promise.resolve();
Expand All @@ -23,13 +23,13 @@ test('Change display style to `none`', async () => {

await (overlay as any).hideOverlay();

expect((overlay as any).iframe).toEqual({ style: { display: 'none' } });
expect((overlay as any).iframe).toEqual({ style: { visibility: 'hidden' } });
});

test('If `activeElement` exists and can be focused, calls `activeElement.focus()`', async () => {
(IframeController.prototype as any).init = function () {
this.iframe = {
style: { display: 'block' },
style: { visibility: 'visible' },
};

return Promise.resolve();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function createOverlayElementsStub() {
src: null,
classList: { add: classListAddStub },
dataset: {},
style: { display: 'none' },
style: { visibility: 'hidden' },
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ beforeEach(() => {
test('Change display style to `block`', async () => {
(IframeController.prototype as any).init = function () {
this.iframe = {
style: { display: 'none' },
style: { visibility: 'hidden' },
focus: () => {},
};

Expand All @@ -24,7 +24,7 @@ test('Change display style to `block`', async () => {

await (overlay as any).showOverlay();

expect((overlay as any).iframe.style.display).toBe('block');
expect((overlay as any).iframe.style.visibility).toBe('visible');
});

test('Calls `iframe.focus()`', async () => {
Expand Down
Loading

0 comments on commit a573e0d

Please sign in to comment.