@@ -157,3 +157,47 @@ test.describe('input: basic', () => {
157
157
} ) ;
158
158
} ) ;
159
159
} ) ;
160
+
161
+ test . describe ( 'input: clear button' , ( ) => {
162
+ test . beforeEach ( ( { skip } ) => {
163
+ skip . rtl ( ) ;
164
+ } ) ;
165
+ test ( 'should clear the input when pressed' , async ( { page } ) => {
166
+ await page . setContent ( `
167
+ <ion-input value="abc" clear-input="true"></ion-input>
168
+ ` ) ;
169
+
170
+ const input = page . locator ( 'ion-input' ) ;
171
+ const clearButton = input . locator ( '.input-clear-icon' ) ;
172
+
173
+ await expect ( input ) . toHaveJSProperty ( 'value' , 'abc' ) ;
174
+
175
+ await clearButton . click ( ) ;
176
+ await page . waitForChanges ( ) ;
177
+
178
+ await expect ( input ) . toHaveJSProperty ( 'value' , '' ) ;
179
+ } ) ;
180
+ /**
181
+ * Note: This only tests the desktop focus behavior.
182
+ * Mobile browsers have different restrictions around
183
+ * focusing inputs, so these platforms should always
184
+ * be tested when making changes to the focus behavior.
185
+ */
186
+ test ( 'should keep the input focused when the clear button is pressed' , async ( { page } ) => {
187
+ await page . setContent ( `
188
+ <ion-input value="abc" clear-input="true"></ion-searchbar>
189
+ ` ) ;
190
+
191
+ const input = page . locator ( 'ion-input' ) ;
192
+ const nativeInput = input . locator ( 'input' ) ;
193
+ const clearButton = input . locator ( '.input-clear-icon' ) ;
194
+
195
+ await input . click ( ) ;
196
+ await expect ( nativeInput ) . toBeFocused ( ) ;
197
+
198
+ await clearButton . click ( ) ;
199
+ await page . waitForChanges ( ) ;
200
+
201
+ await expect ( nativeInput ) . toBeFocused ( ) ;
202
+ } ) ;
203
+ } ) ;
0 commit comments