Skip to content

Commit c6eef27

Browse files
committed
EmptyDOMController - Add count of matching elements in DOM to the dom:not-empty event
1 parent bc05eb1 commit c6eef27

12 files changed

+37
-15
lines changed

dist/empty_dom_controller.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/stimulus-library.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/stimulus-library.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/stimulus-library.modern.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/stimulus-library.modern.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/stimulus-library.module.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/stimulus-library.module.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/stimulus-library.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/stimulus-library.umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/controllers/empty_dom_controller.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ You can then style the controller, or show a nice placeholder when the container
3535

3636
| Value | Type | Purpose | Default |
3737
| --- | --- | --- | --- |
38-
| `scopeSelector` | String | A CSS selector to pass to `querySelectorAll` to limit what elements are included in the count of empty/not-empty | All child elements of controller element |
38+
| `scopeSelector` (Optional) | String | A CSS selector to pass to `querySelectorAll` to limit what elements are included in the count of empty/not-empty | All child elements of controller element |
3939

4040
## ** Events **
4141

@@ -44,7 +44,7 @@ You can then style the controller, or show a nice placeholder when the container
4444
| Event | When | Dispatched on | `event.detail` |
4545
| --- | --- | --- | --- |
4646
| `dom:empty` | When the subtree of the attached element becomes empty | The controller element | - |
47-
| `dom:not-empty` | When the subtree of the attached element is no longer empty | The controller element | - |
47+
| `dom:not-empty` | When the subtree of the attached element is no longer empty | The controller element | `count` - The number of matching elements that are now present |
4848

4949
## ** Side Effects **
5050

@@ -56,13 +56,18 @@ None
5656

5757
## Simple Case
5858

59-
The controller emits an event `dom:empty` when the container becomes empty, and `dom:not-empty` when it is no longer empty. Use those events to hook up other Stimulus actions. This particular example toggles the hide/show of a nice status message when the container is empty.
59+
The controller emits an event `dom:empty` when the container becomes empty, and `dom:not-empty` when it is no longer empty (and for every DOM update that means it is still not empty). Use those events to hook up other Stimulus actions. This particular example toggles the hide/show of a nice status message when the
60+
container is empty.
6061

6162

6263
<!-- tabs:start -->
64+
6365
## ** HTML **
66+
6467
[example](../examples/empty_dom_controller.html.erb ':include :type=code')
68+
6569
## ** HAML **
70+
6671
[example](../examples/empty_dom_controller.html.haml ':include :type=code')
6772
<!-- tabs:end -->
6873

@@ -74,8 +79,12 @@ The selector you specify will be used to `querySelectorAll` the children/subtree
7479
`dom:empty` and `dom:not-empty` events when the results of the query are empty/not empty.
7580

7681
<!-- tabs:start -->
82+
7783
## ** HTML **
84+
7885
[example](../examples/empty_dom_controller_advanced.html.erb ':include :type=code')
86+
7987
## ** HAML **
88+
8089
[example](../examples/empty_dom_controller_advanced.html.haml ':include :type=code')
8190
<!-- tabs:end -->

0 commit comments

Comments
 (0)