@@ -75,25 +75,45 @@ export const SelectableMixin = <T extends Constructor<LitElement>>(
7575
7676 constructor ( ...args : any [ ] ) {
7777 super ( ...args ) ;
78- this . addEventListener ( 'click' , this . _handleClick ) ;
79- this . addEventListener ( 'keydown' , this . handleSelectKeydown ) ;
78+ this . addEventListener ( 'click' , this . #onClick ) ;
79+ this . addEventListener ( 'keydown' , this . #onKeydown ) ;
8080 }
8181
82- private handleSelectKeydown = ( e : KeyboardEvent ) => {
82+ #onKeydown = ( e : KeyboardEvent ) => {
8383 const composePath = e . composedPath ( ) ;
8484 if (
8585 ( this . _selectable || ( this . deselectable && this . selected ) ) &&
8686 composePath . indexOf ( this . selectableTarget ) === 0
8787 ) {
8888 if ( this . selectableTarget === this ) {
8989 if ( e . code !== 'Space' && e . code !== 'Enter' ) return ;
90- this . _toggleSelect ( ) ;
90+ this . #toggleSelect ( ) ;
9191 e . preventDefault ( ) ;
9292 }
9393 }
9494 } ;
9595
96- private _select ( ) {
96+ #onClick = ( e : Event ) => {
97+ const composePath = e . composedPath ( ) ;
98+ if (
99+ ( this . _selectable || ( this . deselectable && this . selected ) ) &&
100+ composePath . indexOf ( this . selectableTarget ) === 0
101+ ) {
102+ this . #toggleSelect( ) ;
103+ }
104+ } ;
105+
106+ #toggleSelect( ) {
107+ // Only allow for select-interaction if selectable is true. Deselectable is ignored in this case, we do not want a DX where only deselection is a possibility..
108+ if ( ! this . selectable ) return ;
109+ if ( this . deselectable === false ) {
110+ this . #select( ) ;
111+ } else {
112+ this . selected ? this . #deselect( ) : this . #select( ) ;
113+ }
114+ }
115+
116+ #select( ) {
97117 if ( ! this . selectable ) return ;
98118 const selectEvent = new UUISelectableEvent ( UUISelectableEvent . SELECTED ) ;
99119 this . dispatchEvent ( selectEvent ) ;
@@ -102,34 +122,14 @@ export const SelectableMixin = <T extends Constructor<LitElement>>(
102122 this . selected = true ;
103123 }
104124
105- private _deselect ( ) {
125+ #deselect ( ) {
106126 if ( ! this . deselectable ) return ;
107127 const selectEvent = new UUISelectableEvent ( UUISelectableEvent . DESELECTED ) ;
108128 this . dispatchEvent ( selectEvent ) ;
109129 if ( selectEvent . defaultPrevented ) return ;
110130
111131 this . selected = false ;
112132 }
113-
114- private _handleClick ( e : Event ) {
115- const composePath = e . composedPath ( ) ;
116- if (
117- ( this . _selectable || ( this . deselectable && this . selected ) ) &&
118- composePath . indexOf ( this . selectableTarget ) === 0
119- ) {
120- this . _toggleSelect ( ) ;
121- }
122- }
123-
124- private _toggleSelect ( ) {
125- // Only allow for select-interaction if selectable is true. Deselectable is ignored in this case, we do not want a DX where only deselection is a possibility..
126- if ( ! this . selectable ) return ;
127- if ( this . deselectable === false ) {
128- this . _select ( ) ;
129- } else {
130- this . selected ? this . _deselect ( ) : this . _select ( ) ;
131- }
132- }
133133 }
134134 // prettier-ignore
135135 return ( SelectableMixinClass as unknown ) as Constructor < SelectableMixinInterface > & T ;
0 commit comments