-
Notifications
You must be signed in to change notification settings - Fork 0
Patch show() and showModal() methods to emit a "show" Event and prevent page scroll; allow subclassing of the component #2
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR patches show()
and showModal()
on wrapped dialogs to emit a show
event, prevents page scrolling when a modal dialog is open, and exports the component class for subclassing.
- Monkey-patch native
show()
/showModal()
to emit ashow
event withdetail.isModal
- Lock and restore page scroll when modal dialogs open and close
- Export
DialogUtils
class to enable subclassing
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/dialog-utils.js | Export component class; add event emission; add scroll lock logic |
package.json | Bump version to 0.2.0 |
README.md | Document new show event and subclassing example |
Comments suppressed due to low confidence (2)
src/dialog-utils.js:1
- Removing the default export in favor of a named export may break existing consumers; consider adding
export default DialogUtils
or bumping to a major version.
export class DialogUtils extends HTMLElement {
src/dialog-utils.js:60
- New behavior for emitting
show
events and scroll locking should be covered by unit/integration tests to verify event detail and overflow restoration.
monkeyPatchShowModalMethod() {
@@ -28,8 +28,12 @@ class DialogUtils extends HTMLElement { | |||
} | |||
|
|||
this.dialog = this.querySelector('dialog'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You assume a <dialog>
is always present; add a null check or guard so that missing dialogs don’t cause runtime errors.
this.dialog = this.querySelector('dialog'); | |
this.dialog = this.querySelector('dialog'); | |
if (!this.dialog) { | |
console.warn('DialogUtils: No <dialog> element found. Initialization aborted.'); | |
return; | |
} |
Copilot uses AI. Check for mistakes.
@@ -28,8 +28,12 @@ class DialogUtils extends HTMLElement { | |||
} | |||
|
|||
this.dialog = this.querySelector('dialog'); | |||
|
|||
this.dialog.addEventListener('show', this.onShow.bind(this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Event listeners are added in connectedCallback
but never removed in disconnectedCallback
, leading to potential memory leaks; consider cleaning them up.
Copilot uses AI. Check for mistakes.
@Copilot What are possible risks of this approach to monkey-patch the native show() and showModal() methods of the HTMLDialogElement? |
This PR introduces three new features:
<dialogs-utils>
will now emit a "show" event. This is achieved by monkey-patching the show() and showModal() methods.<dialog-utils>
is opened as a modal; this is a recommended UX best practice.onShow()
andonClose()
methods.