Skip to content

Commit

Permalink
Move out the querySelector from the connectedCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
dombesz committed Sep 5, 2024
1 parent 1f26a21 commit 16787e9
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions app/components/primer/open_project/sub_header_element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,7 @@ class SubHeaderElement extends HTMLElement {
clearButtonWrapper: HTMLElement | null

connectedCallback() {
this.#waitForCondition(
() => Boolean(this.filterInput),
() => {
this.clearFilterButton = this.querySelector('button.FormControl-input-trailingAction') as HTMLButtonElement
this.clearButtonWrapper = this.clearFilterButton.closest('.FormControl-input-wrap') as HTMLElement

if (this.clearFilterButton) {
this.toggleFilterInputClearButton()
}
}
)
this.#setupFilterInputClearButton();

Check failure on line 13 in app/components/primer/open_project/sub_header_element.ts

View workflow job for this annotation

GitHub Actions / eslint

Delete `;`
}

toggleFilterInputClearButton() {
Expand Down Expand Up @@ -64,6 +54,20 @@ class SubHeaderElement extends HTMLElement {
this.classList.remove('SubHeader--expandedSearch')
}

#setupFilterInputClearButton(){

Check failure on line 57 in app/components/primer/open_project/sub_header_element.ts

View workflow job for this annotation

GitHub Actions / eslint

Insert `·`
this.#waitForCondition(
() => Boolean(this.filterInput),
() => {
this.clearFilterButton = this.querySelector('button.FormControl-input-trailingAction') as HTMLButtonElement
this.clearButtonWrapper = this.clearFilterButton.closest('.FormControl-input-wrap') as HTMLElement

if (this.clearFilterButton) {
this.toggleFilterInputClearButton()
}
}

Check failure on line 67 in app/components/primer/open_project/sub_header_element.ts

View workflow job for this annotation

GitHub Actions / eslint

Insert `,`
)
}

// Waits for condition to return true. If it returns false initially, this function creates a
// MutationObserver that calls body() whenever the contents of the component change.
#waitForCondition(condition: () => boolean, body: () => void) {
Expand Down

0 comments on commit 16787e9

Please sign in to comment.