fix: responsive grid breakpoints for small screens (#41)
CI / build-and-test (pull_request) Successful in 2m47s
CI / build-and-test (pull_request) Successful in 2m47s
Add a columnOpts breakpoint (768px -> 1 column) so widgets stack full-width on mobile instead of staying at 12 columns. Persisting to localStorage is skipped while gridstack's own responsive collapse is active, so narrowing the window can no longer overwrite the saved desktop layout; drag/resize is disabled below the same breakpoint to avoid touch misfires.
This commit is contained in:
@@ -59,6 +59,10 @@ public class DashboardView extends VerticalLayout implements HasDynamicTitle {
|
||||
|
||||
private static final String STORAGE_KEY = "dashboard";
|
||||
|
||||
/** Matches gridstack's {@code columnOpts} breakpoint below which the grid
|
||||
* stacks to a single column (see {@link GridStackLayout#setResponsiveBreakpoint}). */
|
||||
private static final int MOBILE_BREAKPOINT_PX = 768;
|
||||
|
||||
/** A KPI tile is a quarter row wide, so the n-th one starts at 3n. */
|
||||
private static final int KPI_WIDTH = 3;
|
||||
|
||||
@@ -83,6 +87,8 @@ public class DashboardView extends VerticalLayout implements HasDynamicTitle {
|
||||
|
||||
grid.setWidthFull();
|
||||
grid.setStorageKey(STORAGE_KEY);
|
||||
// Below phone/small-tablet width, stack every widget full-width.
|
||||
grid.setResponsiveBreakpoint(MOBILE_BREAKPOINT_PX, 1);
|
||||
grid.addLayoutChangeListener(e -> status.setText(
|
||||
getTranslation("gridstack.status", e.getPositions().size())));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user