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

feat(core): modal background styling #12360

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alexhristov14
Copy link
Contributor

fixes #12210

Copy link

netlify bot commented Sep 3, 2024

Deploy Preview for fundamental-ngx ready!

Name Link
🔨 Latest commit b4b81ef
🔍 Latest deploy log https://app.netlify.com/sites/fundamental-ngx/deploys/66ec639849374f00086cb84b
😎 Deploy Preview https://deploy-preview-12360--fundamental-ngx.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

github-actions bot commented Sep 3, 2024

Visit the preview URL for this PR (updated for commit b4b81ef):

https://fundamental-ngx-gh--pr12360-feat-popover-modal-u-ibnvs3ls.web.app

(expires Sun, 22 Sep 2024 17:51:38 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 41b993ee8e451bd7c6770b342ce142dc886eacff

[focusTrapped]="true"
>
<fd-popover-control>
<button fd-button>preventCloseOnEscapeKey & preventCloseOnEscapeKey</button>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is supposed to say preventCloseOnEscapeKey & preventCloseOnOutsideClick

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But also maybe just go with typically formatted text i.e. "Prevent Close on Escape Key and Prevent Close on Outside Click" because the camel case on these buttons makes me think it's a property or something that the developer can set

Copy link
Member

@mikerodonnell89 mikerodonnell89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple comments above. Also, is it intentional that the opacity of the overlay is different than the opacity for dialog's overlay? I'm wondering if we needed to add a new class and new functionality, or if we can just borrow what's already being used for dialog

@@ -230,12 +231,29 @@ export class PopoverService extends BasePopoverClass {
}
}

/** Changes background theming when modal */
checkModalBackground(): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add unit tests for checkModalBackground()

@@ -230,12 +231,29 @@ export class PopoverService extends BasePopoverClass {
}
}

/** Changes background theming when modal */
checkModalBackground(): void {
if ((!this.closeOnOutsideClick || !this.closeOnEscapeKey) && this.isOpen) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider reducing the repetition in adding/removing classes by consolidating logic where applicable.
for example:

`checkModalBackground(): void {
const bodyClass = 'fd-overlay-active';
const triggerClass = 'fd-popover__modal';

if ((!this.closeOnOutsideClick || !this.closeOnEscapeKey) && this.isOpen) {
    this.addClasses(bodyClass, triggerClass);
} else {
    this.removeClasses(bodyClass, triggerClass);
}

}`

[focusTrapped]="true"
>
<fd-popover-control>
<button fd-button>Prevent Close on Outside Click & on Escape Key</button>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if there was some way to close this after opening, back button maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can close by clicking the popover again. That's why I didn't overlay the button so that it shows that it's intractable even with the closing properties

<div class="fd-docs-flex-display-helper">
<fd-popover [closeOnOutsideClick]="false" [focusAutoCapture]="true" [focusTrapped]="true">
<fd-popover-control>
<button fd-button>Prevent Close on Outside Click</button>
Copy link
Member

@mikerodonnell89 mikerodonnell89 Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I open this example, then click somewhere on the background thus de-focusing the back button, then pressing escape does not close the popover

if ((!this.closeOnOutsideClick || !this.closeOnEscapeKey) && this.isOpen) {
this._renderer.addClass(document.body, bodyClass);
this._renderer.addClass((this._triggerElement as ElementRef).nativeElement, triggerClass);
} else if ((!this.closeOnOutsideClick || !this.closeOnEscapeKey) && !this.isOpen) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also may want to see this removal logic as part of the destroy process for the service

Copy link
Member

@mikerodonnell89 mikerodonnell89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple more comments

Copy link
Member

@mikerodonnell89 mikerodonnell89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two more small comments then we can merge it

// Preventing the focus from leaving the popover body button when the popover is open

ngOnInit(): void {
document.addEventListener('mousedown', this.keepFocusOnButton.bind(this));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaner way to do this would be with the [focusTrapped] input

]
})
export class PopoverClosingExampleComponent {
constructor() {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for the empty constructor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE REQUEST] Add modal property to Popover control
4 participants