You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/api.md
+9-7
Original file line number
Diff line number
Diff line change
@@ -6,8 +6,9 @@
6
6
convert to a Web Component.
7
7
-`options` - An set of parameters.
8
8
9
-
-`options.shadow` - Use shadow DOM rather than light DOM.
10
-
-`options.dispatchEvents` - Will cause dispatchEvent to be called for functions when attribute is not passed (this object should be same type as passed to [Event constructor options](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event#options))
9
+
-`options.shadow` - ("open", "closed", or undefined) Use the specified shadow DOM mode rather than light DOM.
10
+
-`options.events` - Array of camelCasedProps to dispatch as custom events or a Record of event names to their associated [Event constructor options](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event#options).
11
+
- When dispatching events from named properties, "on" is stripped from the beginning of the property name if present, and the result is lowercased: the property `onMyCustomEvent` dispatches as "mycustomevent".
11
12
-`options.props` - Array of camelCasedProps to watch as String values or { [camelCasedProps]: "string" | "number" | "boolean" | "function" | "json" }
12
13
13
14
- When specifying Array or Object as the type, the string passed into the attribute must pass `JSON.parse()` requirements.
@@ -165,7 +166,7 @@ document.body.innerHTML = `
165
166
166
167
When `Function` is specified as the type, attribute values on the web component will be converted into function references when passed into the underlying React component. The string value of the attribute must be a valid reference to a function on `window` (or on `global`).
167
168
168
-
Note: If you want to avoid global functions, instead of passing attribute you can pass `dispatchEvents` object in options and simply listen on events using `addEventListener` on the custom element. See below.
169
+
Note: If you want to avoid global functions, instead of passing an attribute you can pass an `events` object in options, and listen on events using `addEventListener` on the custom element. See below.
169
170
170
171
```js
171
172
functionThemeSelect({ handleClick }) {
@@ -204,7 +205,7 @@ setTimeout(
204
205
205
206
### Event dispatching
206
207
207
-
When `Function` is specified as the type, instead of passing attribute values referencing global methods, you can simply listen on the DOM event.
208
+
As an alternative to using function props, the `events` object insructs r2wc to dispatch a corresponding DOM event that can be listened to on the custom element itself, on ancestor elements using `bubbles`, and outside of any containing shadow DOM using `composed`.
208
209
209
210
```js
210
211
functionThemeSelect({ onSelect }) {
@@ -218,8 +219,7 @@ function ThemeSelect({ onSelect }) {
> Note: `events` and `props` entries should not be used for the same named property. During initial setup, the event handler will overwrite the function property handler, and if the attribute changes after construction, the new function property handler will overwrite the event handler.
0 commit comments