-
Notifications
You must be signed in to change notification settings - Fork 10
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: NativeDialog builder #40
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
For some simili-builders I'm working with on a personal project, I manage scroll locking (somewhat naively) using this: export class ScrollLock {
static #locks = new Map<HTMLElement, { overflow: string; active: Set<ScrollLock> }>();
#element;
#active = $state(false);
constructor(element: HTMLElement, active?: boolean) {
this.#element = element;
if (active) {
this.active = true;
}
$effect.root(() => {
return () => {
this.active = false;
};
});
}
get element() {
return this.#element;
}
get active() {
return this.#active;
}
set active(value) {
if (value === this.#active) {
return;
}
this.#active = value;
const existing = ScrollLock.#locks.get(this.#element);
if (value) {
if (existing) {
existing.active.add(this);
} else {
const overflow = this.#element.style.overflow;
const active = new Set([this]);
ScrollLock.#locks.set(this.#element, { overflow, active });
this.#element.setAttribute('data-scroll-lock', 'true');
this.#element.style.overflow = 'hidden';
}
} else {
if (existing) {
if (existing.active.has(this)) {
existing.active.delete(this);
}
if (!existing.active.size) {
this.#element?.removeAttribute('data-scroll-lock');
this.#element.style.overflow = existing.overflow;
ScrollLock.#locks.delete(this.#element);
}
}
}
}
} |
I love the idea, still haven't had the time to check it out properly, but thank you for the proposal! |
As an FYI, I haven't really played with it for now, it's still just a rough version. I think I can identify a few broken things as it stands:
|
Adds a dialog builder that relies on
HTMLDialogElement
while attempting to fill-in for pending features such as light dismissal for modals (whatwg/html#9373).Using native dialog features also means we can create modals that use
#top-layer
, which means no more need for portals.To do
returnValue