Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

fix: make CPopper's modifiers to be correctly merged #424

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion packages/chakra-ui-core/src/CPopper/CPopper.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@ function flipPlacement (placement) {
}
}

/**
* Call _.merge() for each item of `object` array with the corresponding
* item of `source` array
* @param {*} object The destination Modifiers array.
* @param {*} source The source array.
* @returns Returns merged `array`
*/
function mergeModifiers (object, source) {
if (!Array.isArray(object)) throw new Error('`object` must be an array')

const _source = Array.isArray(source) ? source : [source]

object.forEach((o) => {
const { name } = o
const _s = _source.find(s => s.name === name)
if (_s) merge(o, _s)
})

return object
}

/**
* CPopper component
*
Expand Down Expand Up @@ -153,7 +174,7 @@ const CPopper = {
return ref
},
computedModifiers () {
return merge([
return mergeModifiers([
this.usePortal && {
name: 'preventOverflow',
options: {
Expand Down