Ver código fonte

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 ano atrás
pai
commit
85100e724e
3 arquivos alterados com 12 adições e 6 exclusões
  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 Ver arquivo

@@ -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 Ver arquivo

@@ -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 Ver arquivo

@@ -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) {


Carregando…
Cancelar
Salvar