Skip to content

Commit

Permalink
Toggle switch debounce (#2078)
Browse files Browse the repository at this point in the history
  • Loading branch information
camertron authored Jun 16, 2023
1 parent 2d35263 commit 6bd439d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-ears-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

ToggleSwitch: Remove @debounce annotation in favor of a boolean flag to prevent confusing screen reader output
11 changes: 9 additions & 2 deletions app/components/primer/alpha/toggle_switch.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {controller, target} from '@github/catalyst'
import {debounce} from '@github/mini-throttle/decorators'

@controller
class ToggleSwitchElement extends HTMLElement {
@target switch: HTMLElement
@target loadingSpinner: HTMLElement
@target errorIcon: HTMLElement

private toggling = false

get src(): string | null {
const src = this.getAttribute('src')
if (!src) return null
Expand All @@ -31,14 +32,18 @@ class ToggleSwitchElement extends HTMLElement {
return this.src != null
}

@debounce(300)
async toggle() {
if (this.toggling) return

this.toggling = true

if (this.isDisabled()) {
return
}

if (!this.isRemote()) {
this.performToggle()
this.toggling = false
return
}

Expand All @@ -57,6 +62,8 @@ class ToggleSwitchElement extends HTMLElement {
}

return
} finally {
this.toggling = false
}

this.setSuccessState()
Expand Down
1 change: 0 additions & 1 deletion package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"@github/details-menu-element": "^1.0.12",
"@github/image-crop-element": "^5.0.0",
"@github/include-fragment-element": "^6.1.1",
"@github/mini-throttle": "^2.1.0",
"@github/relative-time-element": "^4.0.0",
"@github/tab-container-element": "^3.1.2",
"@oddbird/popover-polyfill": "^0.2.1",
Expand Down

0 comments on commit 6bd439d

Please sign in to comment.