|
|
@@ -0,0 +1,20 @@
|
|
|
+export default defineNuxtPlugin(() => {
|
|
|
+ if (!import.meta.client) return
|
|
|
+
|
|
|
+ const onBlur = (e: FocusEvent) => {
|
|
|
+ const target = e.target as HTMLElement | null
|
|
|
+ if (!target) return
|
|
|
+
|
|
|
+ const tag = target.tagName
|
|
|
+ if (tag !== 'INPUT' && tag !== 'TEXTAREA') return
|
|
|
+
|
|
|
+ window.setTimeout(() => {
|
|
|
+ window.scrollTo(0, 0)
|
|
|
+ document.body.scrollTop = 0
|
|
|
+ document.documentElement.scrollTop = 0
|
|
|
+ }, 100)
|
|
|
+ }
|
|
|
+
|
|
|
+ // `blur` does not bubble; use capture to listen globally.
|
|
|
+ document.addEventListener('blur', onBlur, true)
|
|
|
+})
|