@@ -64,7 +64,7 @@ export class ThemePickerElement extends LitElement {
6464 private emblaPrevBtn : HTMLButtonElement | null = null
6565 private emblaNextBtn : HTMLButtonElement | null = null
6666 private emblaApi : EmblaCarouselType | null = null
67- private emblaEvents : AbortController | null = null
67+ private emblaControlsBound = false
6868 private lastIsOpen : boolean | null = null
6969 private lastTheme : ThemeId | null = null
7070
@@ -218,29 +218,30 @@ export class ThemePickerElement extends LitElement {
218218 emblaWithEvents . on ( 'select' , this . emblaUpdateHandler )
219219 emblaWithEvents . on ( 'reInit' , this . emblaUpdateHandler )
220220
221- this . emblaEvents = new AbortController ( )
222- const { signal } = this . emblaEvents
221+ if ( ! this . emblaControlsBound ) {
222+ if ( this . emblaPrevBtn ) {
223+ addButtonEventListeners ( this . emblaPrevBtn , ( event ) => {
224+ if ( event . cancelable && ! event . defaultPrevented ) event . preventDefault ( )
225+ try {
226+ this . emblaApi ?. scrollPrev ( )
227+ } catch ( error ) {
228+ handleScriptError ( error , { scriptName : 'ThemePickerElement' , operation : 'embla:scrollPrev' } )
229+ }
230+ } , this )
231+ }
223232
224- if ( this . emblaPrevBtn ) {
225- this . emblaPrevBtn . addEventListener ( 'click' , ( event ) => {
226- event . preventDefault ( )
227- try {
228- this . emblaApi ?. scrollPrev ( )
229- } catch ( error ) {
230- handleScriptError ( error , { scriptName : 'ThemePickerElement' , operation : 'embla:scrollPrev ' } )
231- }
232- } , { signal } )
233- }
233+ if ( this . emblaNextBtn ) {
234+ addButtonEventListeners ( this . emblaNextBtn , ( event ) => {
235+ if ( event . cancelable && ! event . defaultPrevented ) event . preventDefault ( )
236+ try {
237+ this . emblaApi ?. scrollNext ( )
238+ } catch ( error ) {
239+ handleScriptError ( error , { scriptName : 'ThemePickerElement' , operation : 'embla:scrollNext ' } )
240+ }
241+ } , this )
242+ }
234243
235- if ( this . emblaNextBtn ) {
236- this . emblaNextBtn . addEventListener ( 'click' , ( event ) => {
237- event . preventDefault ( )
238- try {
239- this . emblaApi ?. scrollNext ( )
240- } catch ( error ) {
241- handleScriptError ( error , { scriptName : 'ThemePickerElement' , operation : 'embla:scrollNext' } )
242- }
243- } , { signal } )
244+ this . emblaControlsBound = true
244245 }
245246 } catch ( error ) {
246247 this . teardownEmbla ( )
@@ -249,11 +250,6 @@ export class ThemePickerElement extends LitElement {
249250 }
250251
251252 private teardownEmbla ( ) : void {
252- if ( this . emblaEvents ) {
253- this . emblaEvents . abort ( )
254- this . emblaEvents = null
255- }
256-
257253 if ( this . emblaApi ) {
258254 this . emblaApi . destroy ( )
259255 this . emblaApi = null
0 commit comments