Skip to content

Instantly share code, notes, and snippets.

@jayjayjpg
Created August 30, 2022 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayjayjpg/ba7bd57c104a4fc32f40d5460be66983 to your computer and use it in GitHub Desktop.
Save jayjayjpg/ba7bd57c104a4fc32f40d5460be66983 to your computer and use it in GitHub Desktop.
test-user-interactions-in-js-apps-accurately-with-emulated-events-example-2
// 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