Menu
I have managed to create a popup menu. But it does not position under the “button”
[url=https://postimages.org/][img]https://i.postimg.cc/gcfzLVzH/popup.png
How do I put the menu under the “button”?
>How do I put the menu under the "button"?
``<i>
</i> const menu = document.querySelector(".menu");
function popup(menuCell) {
// shift menu or ul to the current cell
// the more button is located in:
menuCell.appendChild(menu);
menu.classList.remove('hide');
}<i>
</i>
`</CODE>
This required handing over the cell having been clicked:
<CODE>
`<i>
</i> document.addEventListener('click', event => {
const row = event.target.closest('tr');
if (row) {
const id = row.dataset.id
if (event.target.classList.contains('more')) {
// pop up menu, hand over the cell having been clicked:
popup(event.target)
}
}
});<i>
</i>
`</CODE>
Having done so I had some trouble: The menu was not visible as the cell's content was overwritten by the CSS:<br/>
<C>
content: url("https://crud.go4webdev.org/icn/more.svg");
</C><br/>
Therefore I had to change this to background-image:
<CODE>
`<i>
</i> .more {
padding: 0px;
background-image: url("https://crud.go4webdev.org/icn/more.svg");
}<i>
</i>
`</CODE>
Then I positioned the menu absolutely:
<CODE>
`<i>
</i> .more {
position: relative;
}
.menu {
position: absolute;
top: 100%;
right: 0;
}<i>
</i>
`</CODE>
BTW: An array can be defined directly without using a JSON string:
<CODE>
`<i>
</i> const data =
[{
"status": "1",
"name": "New"
}, {
"status": "2",
"name": "Done"
}, {
"status": "3",
"name": "Delete"
}];
data.forEach(buildNewList);<i>
</i>
``
>@Sempervivum#1642948 I achieved this by shifting the menu to the table cell where the more button is located in:
> BTW: An array can be defined directly without using a JSON string:
>I get the meny in almost the right place, but not as a popup menu.
>@Sempervivum#1642950 I'm not sure what you intend to achieve.
``<i>
</i>document.addEventListener('click', event => {
const row = event.target.closest('tr');
let moreClicked = false;
if (row) {
if (event.target.classList.contains('more')) {
popup(event.target);
// note that the user clicked inside the more button:
moreClicked = true;
}
}
// if the user clicked outside the more button:
if (!moreClicked) {
// hide menu:
popupmenu.classList.add('hide');
}
});<i>
</i>
``
``<i>
</i>td {
/* make overflow visible: */
/* overflow: hidden; */
text-overflow: ellipsis;
white-space: nowrap;
background-color: var(--lite);
margin-bottom: 5px;
border-bottom: #009;
padding: 10px;
color: var(--black);
/* make td the reference for
absolute positioning: */
position: relative;
}<i>
</i>
``
>@Sempervivum#1643078 Try to make the td the reference for absoute positioning:
right: 0;
</C> to the menu:
<CODE>
`<i>
</i>.menu {
display: inline-block;
position: absolute;
right: 0;
top: 0;
margin-top: 38px;
list-style: none;
background-color: var(--bg);
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 10;
}<i>
</i>
``overflow: hidden;
`>@Sempervivum#1643094 I suspect that there is one more overflow: hidden; for the table or somewhere else.
<th>
position: absolute
>Is not position: absolute causing problem generally?
position: absolute;
`>@Sempervivum#1643094 I suspect that there is one more overflow: hidden;
>Is there any way to fix this?
>@Sempervivum#1643169 No benefit in inventing the wheel again.
0.1.9 — BETA 4.23