Comments (4)
Thanks for the quick reply @FezVrasta, and thank you for pointing me in the right direction. This helped me achieve what I wanted. However I did get to it only after a bit of trial and error. For example, what eventually worked for me was this:
const myExampleModifier = {
enabled: true,
order: 860,
fn: (data: any) => {
const isVisible = this.state.isVisible;
const left = Math.floor(data.popper.left);
const top = Math.floor(data.popper.top);
const newTop = isVisible ? top : top - 10; // Change the top position if popper is hidden
const transform = `translate3d(${left}px, ${newTop}px, 0px)`;
// Update popper, offsets and styles object
const popper = {...data.popper, left, top: newTop};
const offsets = {...data.offsets, popper};
const styles = {...data.styles, opacity, transform};
return {...data, offsets, styles};
}
};
What I did not understand is why it was necessary for me to change the offsets and styles objects to make this work? Is this the correct way I should go to achieve the desired effect? Sorry for the vague question - I am just making sure I am not missing anything as I am still studying this library :)
Thank you for your help.
from react-popper.
Yes sure,
here is where Popper.js computes the styles that need to be applied to the popper element.
After that, the applyStyle
is just going to set the styles that have been computed in the previous step.
react-popper
replaces the applyStyle
modifier with its own React specific code
You can then inject a custom modifier after computeStyles
that replaces the value of the data.styles.transform
with whatever you prefer.
from react-popper.
Bueller? Would be great to know if the solution is a hack or considered idiomatic. :)
from react-popper.
the modifier system is at the core of Popper.js, feel free to use it, definitely not an hack!
from react-popper.
Related Issues (20)
- Top padding for `preventOverflow` not respected in macOS Safari & iOS HOT 2
- Popper fails to fit in within available viewport HOT 3
- Module '"react-popper"' has no exported member 'usePopper' HOT 1
- Warning when running tests. HOT 1
- Position of Popover is wrong, its fixed to top left HOT 2
- react-popper v1.0 and v2.0 can not use in the same project
- Rollup bundling error: "Error: 'default' is not exported by node_modules/react-fast-compare/index.js" HOT 2
- placement error!!! options.placement set 'top' but replace to 'bottom' HOT 1
- usePopper has something wrong with ReactDom.flushSync HOT 9
- Popper not positioning properly when using React.createElement HOT 2
- Will this library be updated to use @floating-ui behind the scenes? Or will it remain on @popperjs HOT 2
- Adding onFirstUpdate function kills the page HOT 5
- Feature: Close on click outside Boolean property HOT 2
- ts error happened when run the Official demo HOT 2
- How to size popper dynamically with detectOverflow HOT 3
- When to use React popper and when to use @floating-ui/react and why? HOT 2
- Arrow position does not follow after flipping the tooltip when using a VirtualElement as reference
- Warning: flushSync was called from inside a lifecycle method. HOT 3
- How to do escapeWithReference in react-popper 2.3.0 HOT 2
- update() && forceUpdate() with createPortal
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-popper.