Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b45dfcd

Browse files
committed
seperate concerns in auto-check-send into a new auto-check-loading event
1 parent 954cfd7 commit b45dfcd

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/index.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,18 @@ function setLoadingState(event: Event) {
9999
const input = event.currentTarget
100100
if (!(input instanceof HTMLInputElement)) return
101101

102+
let message = 'Verifying…'
103+
const setValidity = text => (message = text)
104+
input.dispatchEvent(
105+
new CustomEvent('auto-check-loading', {
106+
bubbles: true,
107+
detail: {setValidity}
108+
})
109+
)
110+
102111
const autoCheckElement = input.closest('auto-check')
103112
if (autoCheckElement instanceof AutoCheckElement && autoCheckElement.required) {
104-
input.setCustomValidity('Verifying…')
113+
input.setCustomValidity(message)
105114
}
106115
}
107116

@@ -152,12 +161,10 @@ async function check(autoCheckElement: AutoCheckElement) {
152161
if (id && id === state.previousValue) return
153162
state.previousValue = id
154163

155-
let message = 'Verifying…'
156-
const setValidity = text => (message = text)
157164
input.dispatchEvent(
158165
new CustomEvent('auto-check-send', {
159166
bubbles: true,
160-
detail: {body, setValidity}
167+
detail: {body}
161168
})
162169
)
163170

@@ -169,10 +176,6 @@ async function check(autoCheckElement: AutoCheckElement) {
169176
return
170177
}
171178

172-
if (autoCheckElement.required) {
173-
input.setCustomValidity(message)
174-
}
175-
176179
if (state.controller) {
177180
state.controller.abort()
178181
} else {

0 commit comments

Comments
 (0)