* Sets the value of the input. The value will be set by simulating * keypresses that correspond to the given value.
(newValue: string)
| 123 | * keypresses that correspond to the given value. |
| 124 | */ |
| 125 | async setValue(newValue: string): Promise<void> { |
| 126 | const inputEl = await this.host(); |
| 127 | await inputEl.clear(); |
| 128 | // We don't want to send keys for the value if the value is an empty |
| 129 | // string in order to clear the value. Sending keys with an empty string |
| 130 | // still results in unnecessary focus events. |
| 131 | if (newValue) { |
| 132 | await inputEl.sendKeys(newValue); |
| 133 | } |
| 134 | |
| 135 | // Some input types won't respond to key presses (e.g. `color`) so to be sure that the |
| 136 | // value is set, we also set the property after the keyboard sequence. Note that we don't |
| 137 | // want to do it before, because it can cause the value to be entered twice. |
| 138 | await inputEl.setInputValue(newValue); |
| 139 | } |
| 140 | } |
no test coverage detected