Skip to content

Commit

Permalink
feat(popup-menu): add data-popup to container
Browse files Browse the repository at this point in the history
This allows to style specific popup menu.
  • Loading branch information
barmac committed Jun 27, 2022
1 parent aa642c9 commit a9dd9ce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/features/popup-menu/PopupMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ PopupMenu.prototype.open = function(element, id, position) {

current.entries = assign({}, entries, headerEntries);

current.container = this._createContainer();
current.container = this._createContainer(id);

if (size(headerEntries)) {
current.container.appendChild(
Expand Down Expand Up @@ -354,7 +354,7 @@ PopupMenu.prototype._emit = function(eventName) {
*
* @return {Object} a DOM container
*/
PopupMenu.prototype._createContainer = function() {
PopupMenu.prototype._createContainer = function(id) {
var container = domify('<div class="djs-popup">'),
position = this._current.position,
className = this._current.className;
Expand All @@ -368,6 +368,8 @@ PopupMenu.prototype._createContainer = function() {

domClasses(container).add(className);

domAttr(container, 'data-popup', id);

return container;
};

Expand Down
18 changes: 17 additions & 1 deletion test/spec/features/popup-menu/PopupMenuSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,18 @@ describe('features/popup', function() {
}));


it('should add `data-popup` to popup menu container', inject(function(popupMenu) {

// when
popupMenu.open({}, 'menu', { x: 100, y: 100 });

// then
var container = getPopupContainer(popupMenu);

expect(container.dataset).to.have.property('popup', 'menu');
}));


it('should throw error when no provider', inject(function(popupMenu) {

// when not registering a provider
Expand Down Expand Up @@ -1456,5 +1468,9 @@ function queryEntry(popupMenu, id) {
}

function queryPopup(popupMenu, selector) {
return domQuery(selector, popupMenu._current.container);
return domQuery(selector, getPopupContainer(popupMenu));
}

function getPopupContainer(popupMenu) {
return popupMenu._current.container;
}

0 comments on commit a9dd9ce

Please sign in to comment.