New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Popper virtual elements #32376
Conversation
I think |
Yup. We already make use of it in the codebase. |
Adds the ability to use objects implementing the virtual element interface as the value for the reference option of a dropdown config.
Yes but if you refer to the check that is due to |
@septatrix nevermind my comment, I've now learned what this is about ;) Sorry for noise. |
I tidied up the commit history a bit. I also thought about adding an example using a virtual element but I do not think it is worthwhile as it would be longer than most other examples and most most of the other options do not really have examples as well. However if you also would want to add an example I would suggest something like I drafted in this codepen which uses virtual elements to provide a custom contextmenu at the cursor position. (The codepen uses some trickery to make bootstrap think the passed object is an element as it does not use a patched version.) |
@XhmikosR should I rebase them again to squash your commits into the previous ones or do PRs get squashed when merging? I only read in the contribution guidelines that you would like to have a clean commit log :D |
All good, we can squash when merging. |
But the reference that is passed in the configuration is not being used for the reference of Popper 🤔 Lines 164 to 175 in 4e7c9e5
So even if you pass the reference as an object, it does not make any change in the dropdown. |
Fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you add the .dropdown-menu-end
class in the .dropdown-menu
, the position of the dropdown is wrong (position is not as per the passed coordinates). But that's not the issue of Popper. Works well without .dropdown-menu-end
.
What exactly do you mean with wrong. It is now to the left of the passed coordinates as long as there is space for it which is what I would expect. Some bad positioning happens at e.g. lower screen edges but that also happens to normal dropdowns. |
Nevermind. It just changes to I did however notice a misbehaving placement in a few cases but that may have been fixed on main by now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Maybe in the future, tooltip/popover can also use this virtual element feature to follow the mouse cursor.
typeof config.reference.getBoundingClientRect !== 'function' | ||
) { | ||
// Popper virtual elements require a getBoundingClientRect method | ||
throw new Error(`${NAME}: Option "reference" provided type "object" without a required "getBoundingClientRect" method.`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we change this to a TypeError
instead of the generic Error
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, missed it 😄
But then it should also be TypeError 🤔
bootstrap/js/src/util/index.js
Lines 119 to 123 in 44667d8
throw new Error( | |
`${componentName.toUpperCase()}: ` + | |
`Option "${property}" provided type "${valueType}" ` + | |
`but expected type "${expectedTypes}".`) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, let's leave it as is for now and we tackle it later.
Adds the ability to use objects implementing the virtual element interface as the value for the reference option of a dropdown config. Co-authored-by: XhmikosR <xhmikosr@gmail.com>
Fixes #32365