File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed
Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -170,6 +170,7 @@ Custom action option | Description
170170` :stop ` | calls ` .stopPropagation() ` on the event before invoking the method
171171` :prevent ` | calls ` .preventDefault() ` on the event before invoking the method
172172` :self ` | only invokes the method if the event was fired by the element itself
173+ ` :!input ` | suppress an event if it was fired while an input element has focus
173174
174175You can register your own action options with the ` Application.registerActionOption ` method.
175176
Original file line number Diff line number Diff line change @@ -30,6 +30,19 @@ export const defaultActionDescriptorFilters: ActionDescriptorFilters = {
3030 return true
3131 }
3232 } ,
33+
34+ input ( { event, value } ) {
35+ if ( value ) return true
36+
37+ const target = event . target
38+ if ( ! ( target instanceof Element ) ) return true
39+
40+ const isInput =
41+ target . tagName === "INPUT" ||
42+ target . tagName === "TEXTAREA" ||
43+ ( target instanceof HTMLElement && target . isContentEditable )
44+ return ! isInput
45+ } ,
3346}
3447
3548export interface ActionDescriptor {
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ export default class EventOptionsTests extends LogControllerTestCase {
77 <div data-controller="c d">
88 <button></button>
99 <details></details>
10+ <input>
1011 </div>
1112 <div id="outside"></div>
1213 `
@@ -178,6 +179,22 @@ export default class EventOptionsTests extends LogControllerTestCase {
178179 this . assertNoActions ( )
179180 }
180181
182+ async "test true input option" ( ) {
183+ await this . setAction ( this . inputElement , "keydown@window->c#log:input" )
184+
185+ await this . triggerEvent ( this . inputElement , "keydown" )
186+
187+ this . assertActions ( { name : "log" , eventType : "keydown" } )
188+ }
189+
190+ async "test false input option" ( ) {
191+ await this . setAction ( this . inputElement , "keydown@window->c#log:!input" )
192+
193+ await this . triggerEvent ( this . inputElement , "keydown" )
194+
195+ this . assertNoActions ( )
196+ }
197+
181198 async "test custom action option callback params contain the controller instance" ( ) {
182199 let lastActionOptions : { controller ?: Controller < Element > } = { }
183200
@@ -313,4 +330,8 @@ export default class EventOptionsTests extends LogControllerTestCase {
313330 get detailsElement ( ) {
314331 return this . findElement ( "details" )
315332 }
333+
334+ get inputElement ( ) {
335+ return this . findElement ( "input" )
336+ }
316337}
You can’t perform that action at this time.
0 commit comments