Skip to content

Commit a5aa5e3

Browse files
committed
Move DOM selector to selectors file for Uppy
1 parent bfdf6da commit a5aa5e3

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/components/Pages/Contact/client/selectors.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export const queryUppyDashboardTarget = (uppyContainer: HTMLElement | null): HTM
140140
}
141141

142142
export type AccessibilityLabelTarget = HTMLInputElement | HTMLTextAreaElement
143+
export type UppyDashboardRoot = HTMLElement
143144

144145
const isAccessibilityLabelTarget = (element: Element): element is AccessibilityLabelTarget => {
145146
if (isInputElement(element)) {
@@ -149,12 +150,20 @@ const isAccessibilityLabelTarget = (element: Element): element is AccessibilityL
149150
return element.tagName === 'TEXTAREA'
150151
}
151152

153+
const isUppyDashboardRoot = (element: Element): element is UppyDashboardRoot => {
154+
return element instanceof HTMLElement && element.matches('.uppy-Dashboard')
155+
}
156+
152157
export const queryAccessibilityLabelTargets = (root: ParentNode): AccessibilityLabelTarget[] => {
153158
return Array.from(root.querySelectorAll('input[type="text"], input[type="email"], textarea')).filter(
154159
isAccessibilityLabelTarget
155160
)
156161
}
157162

163+
export const queryUppyDashboardRoots = (root: ParentNode): UppyDashboardRoot[] => {
164+
return Array.from(root.querySelectorAll('.uppy-Dashboard')).filter(isUppyDashboardRoot)
165+
}
166+
158167
export const queryContactProjectTypeSelect = (root: ParentNode = document): HTMLSelectElement | null => {
159168
const projectTypeSelect = root.querySelector('#project_type')
160169
return projectTypeSelect instanceof HTMLSelectElement ? projectTypeSelect : null

src/components/Pages/Contact/client/upload.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import Audio from '@uppy/audio'
44
import Webcam from '@uppy/webcam'
55

66
import type { ContactFormElements } from './@types'
7-
import { queryAccessibilityLabelTargets, queryUppyDashboardTarget } from './selectors'
7+
import {
8+
queryAccessibilityLabelTargets,
9+
queryUppyDashboardRoots,
10+
queryUppyDashboardTarget,
11+
} from './selectors'
812
import { isUnitTest } from '@components/scripts/utils/environmentClient'
913

1014
export interface UploadController {
@@ -73,7 +77,7 @@ export const ensureUppyGeneratedAccessibility = (root: ParentNode & Node): Mutat
7377
element.setAttribute('aria-label', fallback)
7478
}
7579

76-
root.querySelectorAll(UPPY_DASHBOARD_SELECTOR).forEach(applyUppyDashboardSemantics)
80+
queryUppyDashboardRoots(root).forEach(applyUppyDashboardSemantics)
7781
queryAccessibilityLabelTargets(root).forEach(labelIfMissing)
7882

7983
const observer = new MutationObserver(mutations => {
@@ -89,7 +93,7 @@ export const ensureUppyGeneratedAccessibility = (root: ParentNode & Node): Mutat
8993
}
9094

9195
if ('querySelectorAll' in node) {
92-
node.querySelectorAll(UPPY_DASHBOARD_SELECTOR).forEach(applyUppyDashboardSemantics)
96+
queryUppyDashboardRoots(node as ParentNode).forEach(applyUppyDashboardSemantics)
9397
queryAccessibilityLabelTargets(node as ParentNode).forEach(labelIfMissing)
9498
}
9599
})

0 commit comments

Comments
 (0)