Resize Observer
<mo-resize-observer> | MOResizeObserver
A component that observes one or more elements for resizing.
The resize observer will report changes to the dimensions of the elements it wraps through the
mo-resize
event. When emitted, a collection of
ResizeObserverEntry
objects will be attached to event.detail
that contains the target element and information about
its dimensions.
<div class="resize-observer-overview"> <mo-resize-observer> <div>Resize this box and watch the console π</div> </mo-resize-observer> </div> <script> const container = document.querySelector('.resize-observer-overview'); const resizeObserver = container.querySelector('mo-resize-observer'); resizeObserver.addEventListener('mo-resize', event => { console.log(event.detail); }); </script> <style> .resize-observer-overview div { display: flex; border: solid 2px var(--mo-input-border-color); align-items: center; justify-content: center; text-align: center; padding: 4rem 2rem; } </style>
import { MOResizeObserver } from '@metsooutotec/modes-web-components/dist/react'; const css = ` .resize-observer-overview div { display: flex; border: solid 2px var(--mo-input-border-color); align-items: center; justify-content: center; text-align: center; padding: 4rem 2rem; } `; const App = () => ( <> <div className="resize-observer-overview"> <MOResizeObserver onMoResize={event => console.log(event.detail)}> <div>Resize this box and watch the console π</div> </MOResizeObserver> </div> <style>{css}</style> </> );
Importing
If youβre using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.
To import this component using a bundler:
import '@metsooutotec/modes-web-components/dist/components/resize-observer/resize-observer.js';
To import this component as a React component:
import MOResizeObserver from '@metsooutotec/modes-web-components/dist/react/resize-observer/';
To import this component using a script tag:
<script type="module" src="https://modes-web.metso.com/dist/components/cdn/components/resize-observer/resize-observer.js"></script>
Slots
Name | Description |
---|---|
(default) | One or more elements to watch for resizing. |
Learn more about using slots.
Properties
Name | Description | Reflects | Type | Default |
---|---|---|---|---|
disabled
|
Disables the observer. |
|
boolean
|
false
|
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Learn more about attributes and properties.
Events
Name | React Event | Description | Event Detail |
---|---|---|---|
mo-resize |
onMoResize |
Emitted when the element is resized. |
{ entries: ResizeObserverEntry[] }
|
Learn more about events.