Created
August 30, 2022 16:36
-
-
Save jayjayjpg/ba7bd57c104a4fc32f40d5460be66983 to your computer and use it in GitHub Desktop.
test-user-interactions-in-js-apps-accurately-with-emulated-events-example-2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// file-upload/app/components/upload.js | |
import Component from '@glimmer/component'; | |
import { tracked } from '@glimmer/tracking'; | |
import { action } from '@ember/object'; | |
import { next } from '@ember/runloop'; | |
export default class UploadComponent extends Component { | |
@tracked | |
fileContent = ''; | |
@action | |
handleFileInput(event) { | |
const reader = new FileReader(); | |
reader.onload = (e) => { | |
this.fileContent = e.target.result; | |
next(() => | |
document | |
.querySelector('#text-field') | |
.dispatchEvent(new Event('input')) | |
); | |
}; | |
reader.readAsText(event.target.files[0]); | |
} | |
@action | |
startUpload() { | |
document.querySelector(`#file-upload-field`).click(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment