Skip to content

Commit 8b17c41

Browse files
committed
Patch
1 parent 8233407 commit 8b17c41

File tree

3 files changed

+23
-28
lines changed

3 files changed

+23
-28
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ jobs:
6464
runs-on: ${{ matrix.os }}
6565
steps:
6666
- uses: actions/checkout@v6
67-
- name: Install Selenium
68-
run: |
69-
curl -LsSfO https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
70-
sudo dpkg -i google-chrome-stable_current_amd64.deb || sudo apt-get -f install -y
71-
if: matrix.os == 'ubuntu-latest'
7267
- uses: astral-sh/setup-uv@v7
7368
- run: uv run pytest -m selenium
7469
- uses: codecov/codecov-action@v5

s3file/static/s3file/js/s3file.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Parse XML response from AWS S3 and return the file key.
33
*
4-
* @param {string} responseText - XML response form AWS S3.
4+
* @param {string} responseText - XML response from AWS S3.
55
* @return {string} - Key from response.
66
*/
77
export function getKeyFromResponse(responseText) {
@@ -16,6 +16,7 @@ export function getKeyFromResponse(responseText) {
1616
* @extends HTMLElement
1717
*/
1818
export class S3FileInput extends globalThis.HTMLElement {
19+
static passThroughAttributes = ["accept", "required", "multiple", "class", "style"]
1920
constructor() {
2021
super()
2122
this.keys = []
@@ -34,21 +35,21 @@ export class S3FileInput extends globalThis.HTMLElement {
3435

3536
connectedCallback() {
3637
// Create a hidden file input for the file picker functionality
37-
this._hiddenInput = document.createElement("input")
38-
this._hiddenInput.type = "file"
38+
this._fileInput = document.createElement("input")
39+
this._fileInput.type = "file"
3940

4041
// Sync attributes to hidden input
4142
this._syncAttributesToHiddenInput()
4243

4344
// Listen for file selection on hidden input
44-
this._hiddenInput.addEventListener("change", () => {
45-
this._files = this._hiddenInput.files
45+
this._fileInput.addEventListener("change", () => {
46+
this._files = this._fileInput.files
4647
this.dispatchEvent(new Event("change", { bubbles: true }))
4748
this.changeHandler()
4849
})
4950

5051
// Append elements
51-
this.appendChild(this._hiddenInput)
52+
this.appendChild(this._fileInput)
5253

5354
// Setup form event listeners
5455
this.form?.addEventListener("formdata", this.fromDataHandler.bind(this))
@@ -62,18 +63,17 @@ export class S3FileInput extends globalThis.HTMLElement {
6263
* Sync attributes from custom element to hidden input.
6364
*/
6465
_syncAttributesToHiddenInput() {
65-
if (!this._hiddenInput) return
66+
if (!this._fileInput) return
6667

67-
const attrsToSync = ["accept", "required", "multiple"]
68-
attrsToSync.forEach((attr) => {
68+
S3FileInput.passThroughAttributes.forEach((attr) => {
6969
if (this.hasAttribute(attr)) {
70-
this._hiddenInput.setAttribute(attr, this.getAttribute(attr))
70+
this._fileInput.setAttribute(attr, this.getAttribute(attr))
7171
} else {
72-
this._hiddenInput.removeAttribute(attr)
72+
this._fileInput.removeAttribute(attr)
7373
}
7474
})
7575

76-
this._hiddenInput.disabled = this.hasAttribute("disabled")
76+
this._fileInput.disabled = this.hasAttribute("disabled")
7777
}
7878

7979
/**
@@ -106,8 +106,8 @@ export class S3FileInput extends globalThis.HTMLElement {
106106
// Setting value on file inputs is restricted for security
107107
if (val === "" || val === null) {
108108
this._files = []
109-
if (this._hiddenInput) {
110-
this._hiddenInput.value = ""
109+
if (this._fileInput) {
110+
this._fileInput.value = ""
111111
}
112112
}
113113
}
@@ -190,8 +190,8 @@ export class S3FileInput extends globalThis.HTMLElement {
190190
}
191191

192192
click() {
193-
if (this._hiddenInput) {
194-
this._hiddenInput.click()
193+
if (this._fileInput) {
194+
this._fileInput.click()
195195
}
196196
}
197197

@@ -216,15 +216,15 @@ export class S3FileInput extends globalThis.HTMLElement {
216216
*/
217217
async submitHandler(event) {
218218
event.preventDefault()
219-
this.form.dispatchEvent(new window.CustomEvent("upload"))
220-
await Promise.all(this.form.pendingRquests)
221-
this.form.requestSubmit(event.submitter)
219+
this.form?.dispatchEvent(new window.CustomEvent("upload"))
220+
await Promise.all(this.form?.pendingRquests)
221+
this.form?.requestSubmit(event.submitter)
222222
}
223223

224224
uploadHandler() {
225225
if (this.files.length && !this.upload) {
226226
this.upload = this.uploadFiles()
227-
this.form.pendingRquests = this.form.pendingRquests || []
227+
this.form.pendingRquests = this.form?.pendingRquests || []
228228
this.form.pendingRquests.push(this.upload)
229229
}
230230
}
@@ -289,7 +289,7 @@ export class S3FileInput extends globalThis.HTMLElement {
289289
* Called when observed attributes change.
290290
*/
291291
static get observedAttributes() {
292-
return ["name", "accept", "required", "multiple", "disabled", "id"]
292+
return this.passThroughAttributes.concat(["name", "id"])
293293
}
294294

295295
attributeChangedCallback(name, oldValue, newValue) {

tests/__tests__/s3file.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ describe("S3FileInput", () => {
3737
form.addEventListener = mock.fn(form.addEventListener)
3838
form.appendChild(input)
3939
assert(form.addEventListener.mock.calls.length === 3)
40-
assert(input._hiddenInput !== null)
41-
assert(input._hiddenInput.type === "file")
40+
assert(input._fileInput !== null)
41+
assert(input._fileInput.type === "file")
4242
})
4343

4444
test("changeHandler", () => {

0 commit comments

Comments
 (0)