Skip to content

Commit 05d9114

Browse files
committed
refactor(core): keep widget post-render hook internal
1 parent 1d918ba commit 05d9114

4 files changed

Lines changed: 8 additions & 28 deletions

File tree

docs/api-reference/core/widget.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ Additional inline CSS styles on the top HTML element of the widget. camelCase CS
3939

4040
Additional CSS classnames on the top HTML element.
4141

42-
#### `onAfterRenderHTML` (function, optional) {#onafterrenderhtml-prop}
43-
44-
Called after the widget has rendered HTML into its root element. Receives the root `HTMLElement`.
45-
46-
If a widget subclass implements the protected `onAfterRenderHTML()` method, that method runs before this callback.
47-
4842
#### `_container` (string | HTMLDivElement, optional) {#_container}
4943

5044
Experimental. The container that this widget is being attached to. Default to `viewId`.
@@ -99,7 +93,7 @@ This function is implemented by the specific widget subclass to update the HTML
9993

10094
#### `onAfterRenderHTML` {#onafterrenderhtml}
10195

102-
Optional. Called after `onRenderHTML()` has updated the widget HTML, and before the `onAfterRenderHTML` prop callback.
96+
Optional. Called after `onRenderHTML()` has updated the widget HTML.
10397

10498
#### `onAdd` {#onadd}
10599

docs/api-reference/widgets/widget-tooltip.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import '@deck.gl/widgets/stylesheet.css';
1111

1212
## Usage
1313

14-
Pass `updateWidgetTooltip` as the `onAfterRenderHTML` prop. Descendants with a `data-deck-widget-tooltip` attribute become tooltip anchors.
14+
Call `updateWidgetTooltip` from `onAfterRenderHTML()`. Descendants with a `data-deck-widget-tooltip` attribute become tooltip anchors.
1515

1616
```tsx
1717
class ResetWidget extends Widget {
@@ -27,17 +27,9 @@ class ResetWidget extends Widget {
2727
rootElement
2828
);
2929
}
30-
}
31-
32-
const widget = new ResetWidget({
33-
onAfterRenderHTML: updateWidgetTooltip
34-
});
35-
```
3630

37-
Subclassing remains available when a custom widget always needs the helper:
38-
39-
```ts
40-
protected override onAfterRenderHTML = updateWidgetTooltip;
31+
protected override onAfterRenderHTML = updateWidgetTooltip;
32+
}
4133
```
4234

4335
Tooltip labels are plain text. Set `aria-label` separately when the anchor needs an accessible name, such as an icon-only button. If an anchor also has a native `title`, the helper removes it to avoid competing browser tooltips. The helper shows tooltips on pointer hover and keyboard focus, and hides them on pointer leave, blur, Escape, or the next render.

modules/core/src/lib/widget.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ export type WidgetProps = {
1818
style?: Partial<CSSStyleDeclaration>;
1919
/** Additional CSS class. */
2020
className?: string;
21-
/** Called after the widget has rendered HTML into its root element. */
22-
onAfterRenderHTML?: (rootElement: HTMLElement) => void;
2321
/**
2422
* The container that this widget is being attached to. Default to `viewId`.
2523
* If set to `'root'`, the widget is placed relative to the whole deck.gl canvas.
@@ -37,8 +35,7 @@ export abstract class Widget<
3735
id: 'widget',
3836
style: {},
3937
_container: null,
40-
className: '',
41-
onAfterRenderHTML: undefined!
38+
className: ''
4239
};
4340

4441
/** Unique identifier of the widget. */
@@ -99,7 +96,6 @@ export abstract class Widget<
9996
if (this.rootElement) {
10097
this.onRenderHTML(this.rootElement);
10198
this.onAfterRenderHTML(this.rootElement);
102-
this.props.onAfterRenderHTML?.(this.rootElement);
10399
}
104100
}
105101

test/modules/core/lib/widget-manager.spec.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const mockDeckInstance = {
5454
height: 400
5555
};
5656

57-
test('Widget#onAfterRenderHTML prop runs after protected hook', () => {
57+
test('Widget#onAfterRenderHTML runs after onRenderHTML', () => {
5858
const calls: string[] = [];
5959
class AfterRenderWidget extends TestWidget {
6060
override onRenderHTML(): void {
@@ -66,13 +66,11 @@ test('Widget#onAfterRenderHTML prop runs after protected hook', () => {
6666
}
6767
}
6868

69-
const widget = new AfterRenderWidget({
70-
onAfterRenderHTML: () => calls.push('prop')
71-
});
69+
const widget = new AfterRenderWidget();
7270
widget.rootElement = document.createElement('div');
7371
widget.updateHTML();
7472

75-
expect(calls).toEqual(['render', 'hook', 'prop']);
73+
expect(calls).toEqual(['render', 'hook']);
7674
});
7775

7876
test('WidgetManager#setProps', () => {

0 commit comments

Comments
 (0)