Skip to content
Nana UI

Mutation Observer

View .md Download

Watches its slotted content for DOM changes via MutationObserver and emits nana-mutation with the records. Useful for reacting to attribute, child-list, subtree or character-data changes without wiring observers by hand.

Observed content
Terminal window
npm install @nana-tec/ui-components
import "@nana-tec/ui-components/mutation-observer";
<nana-mutation-observer>
<div>Observed content</div>
</nana-mutation-observer>

Properties

PropertyAttributeTypeDefaultDescription
attrstring | undefinedAttribute names to watch (space-separated), or `*` for all
attrOldValueattr-old-valuebooleanfalseInclude attribute old values in the records
charDatachar-databooleanfalseWatch text content changes
charDataOldValuechar-data-old-valuebooleanfalseInclude character-data old values
childListchild-listbooleanfalseWatch additions/removals of children
disabledbooleanfalseStop observing

Events

EventDescription
nana-mutationFired on change (`detail.mutationList`)

Slots

SlotDescription
(default)The content to observe
EventTypeDescription
nana-mutationCustomEventFired on change (detail.mutationList)
SlotDescription
(default)The content to observe
Explore Mutation Observer interactively Every state, prop, and edge case — with live controls — in Storybook.
View in Storybook