Repository navigation
Offset option for dropdown can be function - #24222
Conversation
| const RIGHT_MOUSE_BUTTON_WHICH = 3 // MouseEvent.which value for the right button (assuming a right-handed mouse) | ||
| const REGEXP_KEYDOWN = new RegExp(`${ARROW_UP_KEYCODE}|${ARROW_DOWN_KEYCODE}|${ESCAPE_KEYCODE}`) | ||
| const POPPER_OFFSET_KEY = 'offset' | ||
| const POPPER_OFFSET_FN_KEY = 'fn' |
There was a problem hiding this comment.
Not a big fan to add new const for that 🤔
There was a problem hiding this comment.
Agree, const is redundant. Updated
| let key = POPPER_OFFSET_KEY | ||
| if (typeof this._config.offset === 'function') { | ||
| key = POPPER_OFFSET_FN_KEY | ||
| } |
There was a problem hiding this comment.
IMO something like that would be enough :
const offsetConf = {}
if (typeof this._config.offset === 'function') {
offsetConf.offsetFn = (data) => this._getOffset(data)
} else {
offsetConf.offset = this._config.offset
}There was a problem hiding this comment.
I agree with your. It's better solution. Const is redundant
_getPopperConfig() {
const offsetConf = {}
if (typeof this._config.offset === 'function') {
offsetConf.fn = (data) => this._getOffset(data)
} else {
offsetConf.offset = this._config.offset
}
const popperConfig = {
placement : this._getPlacement(),
modifiers : {
offset : offsetConf,
flip : {
enabled : this._config.flip
}
}
}
// Disable Popper.js for Dropdown in Navbar
if (this._inNavbar) {
popperConfig.modifiers.applyStyle = {
enabled: !this._inNavbar
}
}
return popperConfig
}|
|
||
| _getOffset(data) { | ||
| const popperOffset = $.extend({}, data.offsets, this._config.offset(data.offsets) || {}) | ||
| Object.keys(popperOffset).forEach((key) => { |
There was a problem hiding this comment.
Sorry to ask I don't know well offset function from Popper.js but why do you need that ?
Ok I read a bit and IMO if you just do return $.extend({}, data.offsets, this._config.offset(data.offsets) || {}) it will be enough here
There was a problem hiding this comment.
data object has many another keys. We need to change only data.offsets and not other. If we return only extended object with data.offsets - Popper is broken
There was a problem hiding this comment.
That's right 👍 but instead of a Foreach you just have to do :
data.offsets = popperOffset
There was a problem hiding this comment.
Yup. Agree :) Sorry don't know how I can stick new changes in this PR romanlex@9be393b
| const offsetConf = {} | ||
| if (typeof this._config.offset === 'function') { | ||
| offsetConf.fn = (data) => this._getOffset(data) | ||
| } else { |
There was a problem hiding this comment.
I was thinking maybe we should remove _getOffset method because that's not something we will use outside of this and remplaced it by :
offsetConf.fn = (data) => {
data.offsets = $.extend({}, data.offsets, this._config.offset(data.offsets) || {})
return data
}Can you give it a try ?
There was a problem hiding this comment.
Remove this method but in my opinion this is less readable. On the other hand, the method is not needed, because obviously not planned to manage offseting inside boostrap
Fix #24208
Offset option can be function (Popper.js)
With this code I can change any dropdown position as on picture
Fix : #24223