Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Expose APIs for clearing focus and selecting item #39

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export default class DetailsMenuElement extends HTMLElement {
preload: boolean;
src: string;
clearFocus(): void;
selectFocusOrFirst(): void;
}

declare global {
Expand Down
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ class DetailsMenuElement extends HTMLElement {
return input instanceof HTMLInputElement ? input : null
}

clearFocus() {
clearFocus(this)
Copy link
Contributor

Choose a reason for hiding this comment

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

A follow up commit (in this PR or a new one) to inline clearFocus would be good for readability.

}

selectFocusOrFirst() {
const details = this.parentElement
if (!details) return
const element = getFocusedMenuItem(details) || sibling(details, true)
if (element) element.click()
}

connectedCallback() {
if (!this.hasAttribute('role') && !this.hasAttribute('input')) this.setAttribute('role', 'menu')

Expand Down
2 changes: 2 additions & 0 deletions index.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ declare class DetailsMenuElement extends HTMLElement {
get src(): string;
set src(url: string): void;
get input(): ?HTMLInputElement;
clearFocus(): void;
selectFocusOrFirst(): void;
}

declare module '@github/details-menu-element' {
Expand Down