fix: keep wide data tables inside their column
This commit is contained in:
1 parent
77d7000df3
commit
8f4bc9a8ef
3 files changed
+63
-5
No files matched your search
@@ -0,0 +1,50 @@
|
|||||||
|
import { Controller } from '@hotwired/stimulus'
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Pins the hover menu of templates/components/dropdown.html.twig to the viewport while it is open.
|
||||||
|
*
|
||||||
|
* The menu sits in the last cell of data tables, whose wrapper scrolls horizontally when a table is
|
||||||
|
* wider than its column (components/datatable.css). A scrolling box clips everything absolutely
|
||||||
|
* positioned inside it, so on the last rows the menu would vanish into a scrollbar. Fixed
|
||||||
|
* positioning takes it out of that box; it stays a descendant of the hover group, so the CSS
|
||||||
|
* group-hover that shows and hides it keeps working unchanged.
|
||||||
|
*
|
||||||
|
* Right-aligned to the button like before, and flipped above it when there is no room below.
|
||||||
|
*/
|
||||||
|
export default class extends Controller {
|
||||||
|
|
||||||
|
static targets = [ 'button', 'menu' ]
|
||||||
|
|
||||||
|
connect () {
|
||||||
|
this.boundPosition = this.position.bind(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
open () {
|
||||||
|
this.position()
|
||||||
|
window.addEventListener('scroll', this.boundPosition, true)
|
||||||
|
window.addEventListener('resize', this.boundPosition)
|
||||||
|
}
|
||||||
|
|
||||||
|
close () {
|
||||||
|
window.removeEventListener('scroll', this.boundPosition, true)
|
||||||
|
window.removeEventListener('resize', this.boundPosition)
|
||||||
|
}
|
||||||
|
|
||||||
|
position () {
|
||||||
|
const button = this.buttonTarget.getBoundingClientRect()
|
||||||
|
const menu = this.menuTarget
|
||||||
|
|
||||||
|
menu.style.position = 'fixed'
|
||||||
|
menu.style.left = `${Math.max(0, button.right - menu.offsetWidth)}px`
|
||||||
|
|
||||||
|
// the menu's own top padding bridges the gap to the button, so the hover is not lost
|
||||||
|
// on the way down; when flipped, it covers the button from below instead
|
||||||
|
const fitsBelow = button.top + menu.offsetHeight <= window.innerHeight
|
||||||
|
menu.style.top = `${fitsBelow ? button.top : Math.max(0, button.bottom - menu.offsetHeight)}px`
|
||||||
|
menu.style.right = 'auto'
|
||||||
|
}
|
||||||
|
|
||||||
|
disconnect () {
|
||||||
|
this.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* A table wider than its column scrolls inside this box, at every width: let overflow, it would
|
||||||
|
* run past the right edge of the page content - out of line with the buttons above it - and make
|
||||||
|
* the whole page scroll sideways. The row menus (components/dropdown.html.twig) are fixed to the
|
||||||
|
* viewport while open, so this box does not clip them.
|
||||||
|
*/
|
||||||
.data-table-wrapper {
|
.data-table-wrapper {
|
||||||
@apply overflow-x-auto lg:overflow-x-visible mb-8;
|
@apply overflow-x-auto mb-8;
|
||||||
}
|
}
|
||||||
|
|
||||||
.data-table-wrapper__inner {
|
.data-table-wrapper__inner {
|
||||||
@apply align-middle inline-block min-w-full overflow-hidden lg:overflow-visible;
|
@apply align-middle inline-block min-w-full;
|
||||||
}
|
}
|
||||||
|
|
||||||
table {
|
table {
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
<div class="relative inline-block text-left group">
|
<div class="relative inline-block text-left group"
|
||||||
<button type="button" class="flex items-center text-gray-400 hover:text-gray-600 focus:outline-hidden focus:ring-0" aria-expanded="true" aria-haspopup="true">
|
{{ stimulus_controller('dropdown') }}
|
||||||
|
{{ stimulus_action('dropdown', 'open', 'mouseenter')|stimulus_action('dropdown', 'close', 'mouseleave') }}>
|
||||||
|
<button type="button" class="flex items-center text-gray-400 hover:text-gray-600 focus:outline-hidden focus:ring-0" aria-expanded="true" aria-haspopup="true" {{ stimulus_target('dropdown', 'button') }}>
|
||||||
<span class="sr-only">Funktionen</span>
|
<span class="sr-only">Funktionen</span>
|
||||||
{{ icon('dots', 'w-6 h-6') }}
|
{{ icon('dots', 'w-6 h-6') }}
|
||||||
</button>
|
</button>
|
||||||
<div class="hidden group-hover:block absolute right-0 top-0 z-10 w-56 origin-top-right pt-4" role="menu" aria-orientation="vertical" aria-labelledby="menu-button" tabindex="-1">
|
<div class="hidden group-hover:block absolute right-0 top-0 z-10 w-56 origin-top-right pt-4" role="menu" aria-orientation="vertical" aria-labelledby="menu-button" tabindex="-1" {{ stimulus_target('dropdown', 'menu') }}>
|
||||||
<div class="rounded-md bg-white shadow-lg ring-1 ring-black/5 focus:outline-hidden">
|
<div class="rounded-md bg-white shadow-lg ring-1 ring-black/5 focus:outline-hidden">
|
||||||
<div class="py-1 menu menu--pulldown" role="none">
|
<div class="py-1 menu menu--pulldown" role="none">
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
|
|||||||
Reference in new issue
Block a user