React Common - Object Structures - positionConfig
Assign this object to the position option of an overlay widget (Popup, Popover, Tooltip, etc.).
To position an element, specify the my, at, and of options. In the following code, the Popup widget's left side is aligned with the target's right side. This configuration reads as follows: "place my left side at the right side of the #target element."
- import React from 'react';
- import 'devextreme/dist/css/dx.common.css';
- import 'devextreme/dist/css/dx.light.css';
- import Popup, {
- Position
- } from 'devextreme-react/popup';
- class App extends React.Component {
- render() {
- return (
- <Popup ... >
- <Position
- my="left"
- at="right"
- of="#target"
- />
- </Popup>
- );
- }
- }
- export default App;
You can use the offset option to further adjust the position.
Possible positions are limited by the Window. To limit them by another element, specify the boundary option. If actual boundaries should be narrower or wider than the boundary element, set the boundaryOffset.
When a specified position exceeds the boundaries, a collision occurs. Use the collision option to specify how such collisions should be resolved.
at
Specifies the target element's side or corner where the overlay element should be positioned.
To set this option, use an object with the x and y fields. These fields specify the target element's horizontal and vertical sides, respectively. Alternatively, you can use a string shortcut from the accepted values list.
- import React from 'react';
- import 'devextreme/dist/css/dx.common.css';
- import 'devextreme/dist/css/dx.light.css';
- import Popup, {
- Position,
- At
- } from 'devextreme-react/popup';
- class App extends React.Component {
- render() {
- return (
- <Popup ... >
- <Position
- at="left top">
- {/* or */}
- <At x="left" y="top" />
- </Position>
- </Popup>
- );
- }
- }
- export default App;
boundary
The boundary element limits possible positions for the overlay element. The default boundary element is Window. If actual boundaries should be narrower or wider than the boundary element, set the boundaryOffset. When a specified position exceeds the boundaries, a collision occurs.
For information on accepted value types, refer to the of option description.
boundaryOffset
Specifies the offset of boundaries from the boundary element.
The offset is specified in pixels. To set this option, use an object with the x and y fields. These fields specify horizontal and vertical offsets, respectively. Alternatively, you can use a string value that indicates the offsets separated by a whitespace character. A positive offset narrows the boundaries; a negative offset widens the boundaries.
In the following code, left and right boundaries are narrowed (x is 50), but top and bottom boundaries are widened (y is -50).
- import React from 'react';
- import 'devextreme/dist/css/dx.common.css';
- import 'devextreme/dist/css/dx.light.css';
- import Popup, {
- Position,
- BoundaryOffset
- } from 'devextreme-react/popup';
- class App extends React.Component {
- render() {
- return (
- <Popup ... >
- <Position
- boundaryOffset="50 -50">
- {/* or */}
- <BoundaryOffset x={50} y={-50} />
- </Position>
- </Popup>
- );
- }
- }
- export default App;
collision
Specifies how to resolve collisions - when the overlay element exceeds the boundary element.
You can use the following collision resolution algorithms:
"flip"
Move the overlay element to the opposite side of the target if that side has more space."fit"
Move the overlay element to the inside of the boundary element."flipfit"
First apply "flip", then "fit"."none"
Ignore the collision.
To set the collision option, use an object with the x and y fields. These fields specify how to resolve horizontal and vertical collisions, respectively. Alternatively, you can use a string shortcut from the accepted values list.
- import React from 'react';
- import 'devextreme/dist/css/dx.common.css';
- import 'devextreme/dist/css/dx.light.css';
- import Popup, {
- Position,
- Collision
- } from 'devextreme-react/popup';
- class App extends React.Component {
- render() {
- return (
- <Popup ... >
- <Position
- collision="flip none">
- {/* or */}
- <Collision x="flip" y="none" />
- </Position>
- </Popup>
- );
- }
- }
- export default App;
my
Specifies the overlay element's side or corner to align with a target element.
To set this option, use an object with the x and y fields. These fields specify the overlay element's horizontal and vertical sides, respectively. Alternatively, you can use a string shortcut from the accepted values list.
- import React from 'react';
- import 'devextreme/dist/css/dx.common.css';
- import 'devextreme/dist/css/dx.light.css';
- import Popup, {
- Position,
- My
- } from 'devextreme-react/popup';
- class App extends React.Component {
- render() {
- return (
- <Popup ... >
- <Position
- my="left top">
- {/* or */}
- <My x="left" y="top" />
- </Position>
- </Popup>
- );
- }
- }
- export default App;
of
This option accepts the following value types:
CSS selector (or jQuery selector if jQuery is used)
App.js- import React from 'react';
- import 'devextreme/dist/css/dx.common.css';
- import 'devextreme/dist/css/dx.light.css';
- import Popup, {
- Position
- } from 'devextreme-react/popup';
- class App extends React.Component {
- render() {
- return (
- <Popup ... >
- <Position
- of="#target"
- />
- </Popup>
- );
- }
- }
- export default App;
-
App.js
- import React from 'react';
- import 'devextreme/dist/css/dx.common.css';
- import 'devextreme/dist/css/dx.light.css';
- import Popup, {
- Position
- } from 'devextreme-react/popup';
- class App extends React.Component {
- constructor(props) {
- super(props);
- this.target = window;
- }
- render() {
- return (
- <Popup>
- <Position
- of={this.target}
- />
- </Popup>
- );
- }
- }
- export default App;
dxEvent (or jQuery.Event if jQuery is used)
The overlay element is positioned at the event.pageX and event.pageY coordinates. In the following example, the Popover widget is positioned at the point where the user has clicked.
App.js- import React from 'react';
- import 'devextreme/dist/css/dx.common.css';
- import 'devextreme/dist/css/dx.light.css';
- import Popover, {
- Position
- } from 'devextreme-react/popover';
- class App extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- target: undefined
- }
- this.setPosition = this.setPosition.bind(this);
- }
- setPosition(e) {
- e.persist();
- this.setState({
- target: e
- });
- }
- render() {
- return (
- <React.Fragment>
- <a id="target" onClick={this.setPosition}>Details</a>
- <Popover>
- <Position
- of={this.state.target}
- />
- </Popover>
- </React.Fragment>
- );
- }
- }
- export default App;
The following value types are more suitable for jQuery:
-
index.js
- $(function() {
- $("#popupContainer").dxPopup({
- // ...
- position: {
- of: $("#target")
- }
- });
- });
-
index.js
- $(function() {
- $("#popupContainer").dxPopup({
- // ...
- position: {
- of: document.getElementById("#target")
- }
- });
- });
offset
The offset is specified in pixels. To set this option, use an object with the x and y fields. These fields specify horizontal and vertical offsets, respectively. Alternatively, you can use a string value that indicates the offsets separated by a whitespace character. A positive offset shifts the element to the right or down; a negative offset shifts it to the left or up.
In the following code, the overlay element is shifted 50 pixels to the right and 25 pixels up.
- import React from 'react';
- import 'devextreme/dist/css/dx.common.css';
- import 'devextreme/dist/css/dx.light.css';
- import Popup, {
- Position,
- Offset
- } from 'devextreme-react/popup';
- class App extends React.Component {
- render() {
- return (
- <Popup ... >
- <Position
- offset="50 -25">
- {/* or */}
- <Offset x={50} y={-25} />
- </Position>
- </Popup>
- );
- }
- }
- export default App;
If you have technical questions, please create a support ticket in the DevExpress Support Center.