Kaynağa Gözat

Fix event delegation

Event delegation only occurs on client-side, check if window exists to
work with server-side (noop).
pull/1/head
TheoryOfNekomata 1 yıl önce
ebeveyn
işleme
85100e724e
3 değiştirilmiş dosya ile 12 ekleme ve 6 silme
  1. +1
    -0
      packages/web/kitchen-sink/react-next/src/pages/categories/blob/index.tsx
  2. +1
    -0
      packages/web/kitchen-sink/react-next/src/pages/categories/number/index.tsx
  3. +10
    -6
      packages/web/kitchen-sink/react-next/src/utils/event.ts

+ 1
- 0
packages/web/kitchen-sink/react-next/src/pages/categories/blob/index.tsx Dosyayı Görüntüle

@@ -974,6 +974,7 @@ const BlobPage: NextPage = () => {
label="Primary Image"
hint="Select any files here"
block
onChange={(e) => console.log(e.currentTarget.files)}
/>
)
}


+ 1
- 0
packages/web/kitchen-sink/react-next/src/pages/categories/number/index.tsx Dosyayı Görüntüle

@@ -210,6 +210,7 @@ const NumberPage: NextPage = () => {
max={100}
tickMarks={[{ label: 'low', value: 25, }, 50]}
enhanced
onChange={(e) => console.log(e.currentTarget.value)}
/>
</div>
</section>


+ 10
- 6
packages/web/kitchen-sink/react-next/src/utils/event.ts Dosyayı Görüntüle

@@ -1,10 +1,14 @@
const TAG_NAME_ELEMENT_CONSTRUCTOR = {
'INPUT': window.HTMLInputElement,
'SELECT': window.HTMLSelectElement,
'TEXTAREA': window.HTMLTextAreaElement,
} as const;

export const delegateTriggerChangeEvent = <T extends HTMLElement>(target: T, value?: unknown) => {
if (typeof window === 'undefined') {
return;
}

const TAG_NAME_ELEMENT_CONSTRUCTOR = {
'INPUT': window.HTMLInputElement,
'SELECT': window.HTMLSelectElement,
'TEXTAREA': window.HTMLTextAreaElement,
} as const;

const { [target.tagName as keyof typeof TAG_NAME_ELEMENT_CONSTRUCTOR]: elementCtor } = TAG_NAME_ELEMENT_CONSTRUCTOR;

if (!elementCtor) {


Yükleniyor…
İptal
Kaydet