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

upgrade to [email protected] #146

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"npm-run-all": "^4.1.5",
"prettier": "^3.1.0",
"ts-node": "^10.9.1",
"typescript": "5.1.6"
"typescript": "^5.2.2"
},
"lint-staged": {
"*.{js,ts}": [
Expand Down
26 changes: 19 additions & 7 deletions src/index-fn.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
interface PopoverToggleTargetElementInvoker {
popoverTargetElement: HTMLElement | null;
popoverTargetAction: 'toggle' | 'show' | 'hide';
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLButtonElement/popoverTargetAction) */
popoverTargetAction: string;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLButtonElement/popoverTargetElement) */
popoverTargetElement: Element | null;
}

declare global {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent) */
interface ToggleEvent extends Event {
oldState: string;
newState: string;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent/newState) */
readonly newState: string;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent/oldState) */
readonly oldState: string;
}

interface HTMLElement {
popover: 'auto' | 'manual' | null;
showPopover(): void;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/popover) */
popover: string | null;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/hidePopover) */
hidePopover(): void;
togglePopover(): void;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/showPopover) */
showPopover(): void;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/togglePopover) */
togglePopover(force?: boolean): void;
}

/* eslint-disable @typescript-eslint/no-empty-interface */
interface HTMLButtonElement extends PopoverToggleTargetElementInvoker {}
interface HTMLInputElement extends PopoverToggleTargetElementInvoker {}
/* eslint-enable @typescript-eslint/no-empty-interface */

interface Window {
ToggleEvent: ToggleEvent;
}
Expand Down
26 changes: 19 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
import { apply, isSupported } from './popover.js';

interface PopoverToggleTargetElementInvoker {
popoverTargetElement: HTMLElement | null;
popoverTargetAction: 'toggle' | 'show' | 'hide';
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLButtonElement/popoverTargetAction) */
popoverTargetAction: string;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLButtonElement/popoverTargetElement) */
popoverTargetElement: Element | null;
}

declare global {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent) */
interface ToggleEvent extends Event {
oldState: string;
newState: string;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent/newState) */
readonly newState: string;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent/oldState) */
readonly oldState: string;
}

interface HTMLElement {
popover: 'auto' | 'manual' | null;
showPopover(): void;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/popover) */
popover: string | null;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/hidePopover) */
hidePopover(): void;
togglePopover(): void;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/showPopover) */
showPopover(): void;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/togglePopover) */
togglePopover(force?: boolean): void;
}

/* eslint-disable @typescript-eslint/no-empty-interface */
interface HTMLButtonElement extends PopoverToggleTargetElementInvoker {}
interface HTMLInputElement extends PopoverToggleTargetElementInvoker {}
/* eslint-enable @typescript-eslint/no-empty-interface */

interface Window {
ToggleEvent: ToggleEvent;
}
Expand Down
6 changes: 3 additions & 3 deletions src/popover-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
element: HTMLButtonElement | HTMLInputElement,
) {
const popover = element.popoverTargetElement;
if (!popover) {
if (!(popover instanceof HTMLElement)) {
return;
}
const visibility = getPopoverVisibilityState(popover);
Expand Down Expand Up @@ -125,7 +125,7 @@
): HTMLElement | undefined {
while (node) {
const nodePopover = (node as HTMLButtonElement).popoverTargetElement;
if (nodePopover) return nodePopover;
if (nodePopover instanceof HTMLElement) return nodePopover;
node = node.parentElement || getRootNode(node);
if (node instanceof ShadowRoot) node = node.host;
if (node instanceof Document) return;
Expand Down Expand Up @@ -206,7 +206,7 @@
);
let descendant: Node | null = walker.currentNode;
while (descendant) {
// TODO: this is not spec compliant

Check warning on line 209 in src/popover-helpers.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected 'todo' comment: 'TODO: this is not spec compliant'
if (isFocusable(descendant as HTMLElement)) {
return descendant;
}
Expand Down Expand Up @@ -410,7 +410,7 @@
initialAriaExpandedValue.set(el, el.getAttribute('aria-expanded'));
}
const popover = el.popoverTargetElement;
if (popover && popover.popover === 'auto') {
if (popover instanceof HTMLElement && popover.popover === 'auto') {
el.setAttribute('aria-expanded', String(force));
} else {
const initialValue = initialAriaExpandedValue.get(el);
Expand Down