Skip to content

Commit 6492dce

Browse files
committed
docs: document event kebabcase
1 parent c209633 commit 6492dce

File tree

7 files changed

+39
-10
lines changed

7 files changed

+39
-10
lines changed

e2e/docs-e2e/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "docs-e2e",
33
"description": "",
4-
"private": true,
54
"author": "",
65
"devDependencies": {
76
"@playwright/test": "1.54.1",
@@ -10,6 +9,7 @@
109
"keywords": [],
1110
"license": "ISC",
1211
"main": "index.js",
12+
"private": true,
1313
"scripts": {
1414
"test": "pnpm exec playwright test --config=playwright.config.ts --project=chromium",
1515
"test-ui": "pnpm exec playwright test --config=playwright.config.ts --project=chromium --ui"

e2e/qwik-react-e2e/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"name": "qwik-react-test-app",
33
"description": "Qwik react test app",
4-
"engines": {
5-
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
6-
},
7-
"private": true,
84
"devDependencies": {
95
"@qwik.dev/react": "workspace:*",
106
"@types/react": "19.1.13",
117
"@types/react-dom": "19.1.7",
128
"react": "19.1.1",
139
"react-dom": "19.1.1"
1410
},
11+
"engines": {
12+
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
13+
},
14+
"private": true,
1515
"scripts": {
1616
"build": "qwik build",
1717
"build.client": "vite build",

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@
190190
"build.packages.insights": "pnpm -C ./packages/insights/ run build",
191191
"build.platform": "tsx --require ./scripts/runBefore.ts scripts/index.ts --platform-binding",
192192
"build.platform.copy": "tsx --require ./scripts/runBefore.ts scripts/index.ts --platform-binding-wasm-copy",
193+
"build.qwik-react": "tsx --require ./scripts/runBefore.ts scripts/index.ts --tsc --qwikreact",
193194
"build.qwik-router": "tsx --require ./scripts/runBefore.ts scripts/index.ts --tsc --qwikrouter",
194195
"build.router": "tsx --require ./scripts/runBefore.ts scripts/index.ts --tsc --qwikrouter --api",
195-
"build.qwik-react": "tsx --require ./scripts/runBefore.ts scripts/index.ts --tsc --qwikreact",
196196
"build.validate": "tsx --require ./scripts/runBefore.ts scripts/index.ts --tsc --qwik --api --eslint --qwikrouter --platform-binding --wasm --validate",
197197
"build.vite": "tsx --require ./scripts/runBefore.ts scripts/index.ts --tsc --qwik --insights --api --qwikrouter --eslint --platform-binding-wasm-copy",
198198
"build.wasm": "tsx --require ./scripts/runBefore.ts scripts/index.ts --wasm",
@@ -236,11 +236,11 @@
236236
"test.e2e.firefox": "playwright test starters --browser=firefox --config starters/playwright.config.ts",
237237
"test.e2e.integrations.chromium": "playwright test e2e/adapters-e2e/tests --project=chromium --config e2e/adapters-e2e/playwright.config.ts",
238238
"test.e2e.integrations.webkit": "playwright test e2e/adapters-e2e/tests --project=webkit --config e2e/adapters-e2e/playwright.config.ts",
239+
"test.e2e.qwik-react.chromium": "playwright test e2e/qwik-react-e2e/tests --project=chromium --config e2e/qwik-react-e2e/playwright.config.ts",
240+
"test.e2e.qwik-react.webkit": "playwright test e2e/qwik-react-e2e/tests --project=webkit --config e2e/qwik-react-e2e/playwright.config.ts",
239241
"test.e2e.router": "playwright test starters/e2e/qwikrouter --browser=chromium --config starters/playwright.config.ts",
240242
"test.e2e.run": "tsm scripts/e2e-cli.ts",
241243
"test.e2e.webkit": "playwright test starters --browser=webkit --config starters/playwright.config.ts",
242-
"test.e2e.qwik-react.chromium": "playwright test e2e/qwik-react-e2e/tests --project=chromium --config e2e/qwik-react-e2e/playwright.config.ts",
243-
"test.e2e.qwik-react.webkit": "playwright test e2e/qwik-react-e2e/tests --project=webkit --config e2e/qwik-react-e2e/playwright.config.ts",
244244
"test.rust": "make test",
245245
"test.rust.bench": "make benchmark",
246246
"test.rust.update": "make test-update",

packages/docs/src/routes/docs/(qwik)/core/events/index.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ contributors:
2323
- Balastrong
2424
- Jemsco
2525
- shairez
26-
updated_at: '2024-01-09T20:55:11Z'
26+
- wmertens
27+
updated_at: '2025-10-26T00:00:00Z'
2728
created_at: '2023-03-20T23:45:13Z'
2829
---
2930

@@ -299,6 +300,10 @@ export const Button = component$<ButtonProps>(({ onTripleClick$ }) => {
299300

300301
> Notice the use of the `QRL` type in `onTripleClick$: QRL<() => void>;`. It is like wrapping a function in `$()` but at the type level. If you had `const greet = $(() => "hi 👋");` and hovered over 'greet', you would see that 'greet' is of type `QRL<() => "hi 👋">`
301302
303+
Event names are case sensitive, but all DOM events except for `DOMContentLoaded` are lowercase. For a better DX, event names are always lowercased, so `onTripleClick$` becomes `tripleclick` under the hood.
304+
305+
To listen for a custom event with uppercase letters, you must use kebab-case. For example, to listen for a custom event named `CustomEvent`, you would use `on-Custom-Event$` or `on-custom-event$`. The handler would then be called for events named: `CustomEvent`, `-custom-event`, `Custom-event` and `-customEvent`. In practice, this combining of events should not be a problem, but you can check the exact event name in the handler if needed.
306+
302307
## Window and Document Events
303308

304309
So far, the discussion has focused on listening to events originating from elements. There are events such as `scroll` and `mousemove` that need to be listened to on the `window` or `document`. Qwik allows this by providing the `document:on` and `window:on` prefixes when listening for events.

packages/qwik/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@
205205
"url": "https://github.com/QwikDev/qwik.git",
206206
"directory": "packages/qwik"
207207
},
208-
"sideEffects": false,
209208
"scripts": {
210209
"build.insights": "cd src/insights && vite build --mode lib --emptyOutDir"
211210
},
211+
"sideEffects": false,
212212
"type": "module",
213213
"types": "./public.d.ts"
214214
}

packages/qwik/src/core/readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ Register a listener on the current component's host element.
160160

161161
Used to programmatically add event listeners. Useful from custom `use*` methods, which do not have access to the JSX. Otherwise, it's adding a JSX listener in the `<div>` is a better idea.
162162

163+
Event names are converted to lowercase (except for `DOMContentLoaded`). If you need to listen to a case-sensitive custom event, use kebab-case. For example, to listen to `CustomEvent`, use `-Custom-Event` or `-custom-event`. This will listen for `CustomEvent`, but also for `-custom-event`, `Custom-event` and `-customEvent`. In practice, this should not be a problem. You can always check the exact event name in the handler if needed.
164+
163165
@see `useOn`, `useOnWindow`, `useOnDocument`.
164166

165167
@public
@@ -170,6 +172,8 @@ Register a listener on `window`.
170172

171173
Used to programmatically add event listeners. Useful from custom `use*` methods, which do not have access to the JSX.
172174

175+
Event names are converted to lowercase (except for `DOMContentLoaded`). If you need to listen to a case-sensitive custom event, use kebab-case. For example, to listen to `CustomEvent`, use `-Custom-Event` or `-custom-event`. This will listen for `CustomEvent`, but also for `-custom-event`, `Custom-event` and `-customEvent`. In practice, this should not be a problem. You can always check the exact event name in the handler if needed.
176+
173177
@see `useOn`, `useOnWindow`, `useOnDocument`.
174178

175179
<docs code="./examples.tsx#use-on-window"/>
@@ -182,6 +186,8 @@ Register a listener on `document`.
182186

183187
Used to programmatically add event listeners. Useful from custom `use*` methods, which do not have access to the JSX.
184188

189+
Event names are converted to lowercase (except for `DOMContentLoaded`). If you need to listen to a case-sensitive custom event, use kebab-case. For example, to listen to `CustomEvent`, use `-Custom-Event` or `-custom-event`. This will listen for `CustomEvent`, but also for `-custom-event`, `Custom-event` and `-customEvent`. In practice, this should not be a problem. You can always check the exact event name in the handler if needed.
190+
185191
@see `useOn`, `useOnWindow`, `useOnDocument`.
186192

187193
<docs code="./examples.tsx#use-on-document"/>

packages/qwik/src/core/use/use-on.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ export type EventQRL<T extends string = AllEventKeys> =
2323
* Used to programmatically add event listeners. Useful from custom `use*` methods, which do not
2424
* have access to the JSX. Otherwise, it's adding a JSX listener in the `<div>` is a better idea.
2525
*
26+
* Event names are converted to lowercase (except for `DOMContentLoaded`). If you need to listen to
27+
* a case-sensitive custom event, use kebab-case. For example, to listen to `CustomEvent`, use
28+
* `-Custom-Event` or `-custom-event`. This will listen for `CustomEvent`, but also for
29+
* `-custom-event`, `Custom-event` and `-customEvent`. In practice, this should not be a problem.
30+
* You can always check the exact event name in the handler if needed.
31+
*
2632
* @public
2733
* @see `useOn`, `useOnWindow`, `useOnDocument`.
2834
*/
@@ -40,6 +46,12 @@ export const useOn = <T extends KnownEventNames>(event: T | T[], eventQrl: Event
4046
* Used to programmatically add event listeners. Useful from custom `use*` methods, which do not
4147
* have access to the JSX.
4248
*
49+
* Event names are converted to lowercase (except for `DOMContentLoaded`). If you need to listen to
50+
* a case-sensitive custom event, use kebab-case. For example, to listen to `CustomEvent`, use
51+
* `-Custom-Event` or `-custom-event`. This will listen for `CustomEvent`, but also for
52+
* `-custom-event`, `Custom-event` and `-customEvent`. In practice, this should not be a problem.
53+
* You can always check the exact event name in the handler if needed.
54+
*
4355
* @public
4456
* @see `useOn`, `useOnWindow`, `useOnDocument`.
4557
*
@@ -73,6 +85,12 @@ export const useOnDocument = <T extends KnownEventNames>(event: T | T[], eventQr
7385
* Used to programmatically add event listeners. Useful from custom `use*` methods, which do not
7486
* have access to the JSX.
7587
*
88+
* Event names are converted to lowercase (except for `DOMContentLoaded`). If you need to listen to
89+
* a case-sensitive custom event, use kebab-case. For example, to listen to `CustomEvent`, use
90+
* `-Custom-Event` or `-custom-event`. This will listen for `CustomEvent`, but also for
91+
* `-custom-event`, `Custom-event` and `-customEvent`. In practice, this should not be a problem.
92+
* You can always check the exact event name in the handler if needed.
93+
*
7694
* @public
7795
* @see `useOn`, `useOnWindow`, `useOnDocument`.
7896
*

0 commit comments

Comments
 (0)