Skip to content

Absolute

The Absolute component is a structural element designed to wrap content and position it precisely, independent of the normal document structure. It is ideal for creating dynamic notifications, pop-ups, overlays, moving nameplates, and other UI elements that require precise placement.

By default, the Absolute component positions its content relative to the closest Relative component parent. If no Relative component is present, it positions relative to the body.

The primary use case for the Absolute component is to position nested content precisely within a document. The component lets you define offsets using the top, left, right, and bottom properties.

import Relative from '@components/Layout/Relative/Relative';
import Absolute from '@components/Layout/Absolute/Absolute';
import Block from '@components/Layout/Block/Block';
const App = () => {
return (
<Relative>
<Absolute top="50px" right="50px">
<Block>Content with top and right offset by 50px</Block>
</Absolute>
</Relative>
);
};
export default App;
Prop NameTypeDefaultDescription
styleJSX.CSSProperties{}Inline styles to apply directly to the component’s root element.
classstring""Additional CSS classes to apply to the component
refHTMLDivElementundefinedRetrieves the component’s DOM element and assigns it to a variable.
top, left, right, bottomstring""Specify the position offset of the Absolute component. It accepts any valid css unit value
onActionRecord<string, (scope?: string, ...args: any[]) => void>undefinedAllows you to add custom navigation action handlers to the component. See the Navigation component documentation for details.
anchorstring | HTMLElementundefinedLinks navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement.

The primary purpose of the Absolute component is to position content precisely. To achieve optimal control, it is recommended to nest the Absolute component within a Relative component. This allows the Relative component to act as a bounding box, ensuring the Absolute component is positioned relative to it rather than the document or screen.

import Relative from '@components/Layout/Relative/Relative';
import Absolute from '@components/Layout/Absolute/Absolute';
import Block from '@components/Layout/Block/Block';
const App = () => {
return (
<Relative style={{ width: '300px', height: '200px', border: '1px solid black' }}>
<Block>Normally positioned content</Block>
<Absolute top="20px" left="40px">
This content is positioned 20px from the top and 40px from the left of the Relative container.
</Absolute>
<Absolute bottom="0" right="0">
Positioned at the bottom right corner of the Relative container.
</Absolute>
</Relative>
);
};
export default App;

To access the HTML DOM element of the Absolute component.

  1. Declare a variable to hold the ref but don’t initialize it with a value
  2. The declared value should have a type of HTMLDivElement.
  3. Set the declared variable as the value of the ref prop of the Absolute component
import Relative from '@components/Layout/Relative/Relative';
import Absolute from '@components/Layout/Absolute/Absolute';
import Block from '@components/Layout/Block/Block';
const App = () => {
let absoluteRef!: HTMLDivElement;
return (
<Relative>
<Absolute ref={absoluteRef} top="50px" right="50px">
<Block>Content with top and right offset by 50px</Block>
</Absolute>
</Relative>
);
};
export default App;

Now you can access the HTML element of the component with absoluteRef and make modifications to it if needed.