Skip to content

Commit

Permalink
Emit an input event primer-text-field#clearContents. (primer#3062)
Browse files Browse the repository at this point in the history
Co-authored-by: Cameron Dutro <camertron@gmail.com>
  • Loading branch information
dombesz and camertron committed Sep 10, 2024
1 parent c8dfea4 commit b45ef04
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-vans-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': minor
---

Trigger an input event when the primer-text-field clear button is pressed.
1 change: 1 addition & 0 deletions lib/primer/forms/primer_text_field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class PrimerTextFieldElement extends HTMLElement {
clearContents() {
this.inputElement.value = ''
this.inputElement.focus()
this.inputElement.dispatchEvent(new Event('input', { bubbles: true, cancelable: false }))
}

clearError(): void {
Expand Down
12 changes: 12 additions & 0 deletions test/system/alpha/text_field_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,20 @@ def test_clear_button
find("input[type=text]").fill_in(with: "foobar")
assert_equal find("input[type=text]").value, "foobar"

evaluate_multiline_script(<<~JS)
window.inputTriggered = false
document.querySelector('input[type=text]').addEventListener('input', (_event) => {
window.inputTriggered = true
})
JS

refute page.evaluate_script("window.inputTriggered")

find("button").click
assert_equal find("input[type=text]").value, ""

assert page.evaluate_script("window.inputTriggered")
end

def test_auto_check_error
Expand Down

0 comments on commit b45ef04

Please sign in to comment.