-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
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
Restore offset option for dropdown component #32443
Conversation
My problem is that I have no idea why it was removed in the first place, and if there was some special reason... |
It think because popper changes the way to configure the offset. |
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.
Thanks for the PR 🙂 @joke2k
I have left a few comments, it is better to have the offset
option in the configuration.
@joke2k Can you make the update, please? |
It is now complete for dropdown though but the same should be done for Tooltip/Popover also, IMO. |
ce7537c
to
01c79dd
Compare
If I'm not wrong, scrollspy offset is under the same use-case. In alpha v5 is not working either. |
I checked into bs4 and bs5 but ScrollSpy component never used Popper for its offset. |
a1a1be8
to
a4008cd
Compare
@@ -289,6 +289,20 @@ class Dropdown extends BaseComponent { | |||
return this._element.closest(`.${CLASS_NAME_NAVBAR}`) !== null | |||
} | |||
|
|||
_getOffset() { |
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.
@rohit2sharma95 this seems to be duplicated. Might be worth checking at a later time if we it makes sense to deduplicate this. Lower priority right 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.
Yes, should tackle it in a new PR later?
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.
I'm trying to deduplicate this into utils/index.js
and I was wondering if we can do the same for _getPopperConfig
...
but the function signature becoming a little bit weird:
const getPopperOffsets = (element, config) => {
if (typeof offset === 'string') {
return offset.split(',').map(val => Number.parseInt(val, 10))
}
if (typeof offset === 'function') {
return popperData => offset(popperData, element)
}
return offset
}
const getPopperConfig = (element, placement, offset, modifiers, options) => {
const defaultBsConfig = {
placement: placement,
modifiers: [...(modifiers || [])],
...(options || {})
}
if (offset) {
defaultBsConfig.modifiers.push({
name: 'offset',
options: {
offset: getPopperOffsets(element, offset)
}
})
}
return defaultBsConfig
}
the element
is necessary because offset configured as function needs it for the second parameter.
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.
No need to do this now. We'll have plenty of time after this lands :)
0e25508
to
4839b82
Compare
I thought the offset would not only be applied when scrolling manually to detect which button should be highlighted but also when clicking on the button to have such offset applied in the scroll. My bad |
I also notice if someone wants to pass the So if the user passes only one modifier in the array of Lines 318 to 322 in 86802f7
So few options should be maintained individually by Bootstrap that are customized by bootstrap. For example, the default value for And it should be mentioned in the docs that if someone passes the configuration via |
@rohit2sharma95 @XhmikosR Should we open an issue or PR to track that separately so we can merge this? |
Yes, either the docs should be updated or the way of merging the popperConfig in the plugins. |
6836897
to
d6ccfe2
Compare
d6ccfe2
to
522626f
Compare
With Popper 2.0 the dropdown offset option was removed from bootstrap but remains in the documentation and in our ❤️ s.
This is an humble PR to restore them.
Fixes #32418