Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do Not Merge: test adding an autofill button to file input #1214

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion packages/storybook/stories/va-file-input-uswds.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react/prop-types */
import React, { useState } from 'react';
import {VaFileInput} from '@department-of-veterans-affairs/web-components/react-bindings';
import {VaFileInput, VaButton} from '@department-of-veterans-affairs/web-components/react-bindings';
import { getWebComponentDocs, propStructure, StoryDocs } from './wc-helpers';

const fileInputDocs = getWebComponentDocs('va-file-input');
Expand All @@ -16,6 +16,35 @@ export default {
},
};

function loadURLToInputFiled(url){
getImgURL(url, (imgBlob)=>{
// Load img blob to input
// WIP: UTF8 character error
let fileName = 'header-logo.png'
let file = new File([imgBlob], fileName,{type:"image/png", lastModified:new Date().getTime()}, 'utf-8');
let container = new DataTransfer();
container.items.add(file);
let inputs = document.querySelectorAll('va-file-input')
inputs.forEach((input) =>{
input.shadowRoot.querySelector('#fileInputField')
input.files = container.files;
let e = new Event("change")
input.dispatchEvent(e)
})

})
}
// xmlHTTP return blob respond
function getImgURL(url, callback){
var xhr = new XMLHttpRequest();
xhr.onload = function() {
callback(xhr.response);
};
xhr.open('GET', url);
xhr.responseType = 'blob';
xhr.send();
}

const defaultArgs = {
'label': 'Select a file to upload',
'name': 'my-file-input',
Expand Down Expand Up @@ -45,6 +74,7 @@ const Template = ({
children
}) => {
return (
<>
<VaFileInput
label={label}
name={name}
Expand All @@ -58,6 +88,10 @@ const Template = ({
header-size={headerSize}
children={children}
/>
<VaButton
onClick={() => {loadURLToInputFiled('https://i.imgur.com/xyKcUlt.jpeg')}}
/>
</>
);
};

Expand Down
Loading