web-components icon indicating copy to clipboard operation
web-components copied to clipboard

[dialog] Add APIs to set position and dimension

Open DiegoCardoso opened this issue 5 years ago • 5 comments

Developer could be able to set the coordinates (top, left) and dimension (width, height) of the overlay.

Two things that could be part of this:

  • A draggable event after dragging is done
  • Update resize event to add the top and left positions to its detail data (the reason is that so, dialog flow could sync these values on resize)

DiegoCardoso avatar Feb 19 '20 11:02 DiegoCardoso

Hope to see this feature in next release.

ado2000 avatar Aug 09 '20 15:08 ado2000

When will this feature available ?

osenbg avatar Nov 06 '21 09:11 osenbg

  • We should avoid setting width/height on a postitioned-but-not-sized Dialog to avoid the problem that dragging currently has: https://github.com/vaadin/web-components/issues/436
  • The left/top position should be reflected back to the server when a drag-move ends, so that the getters return the new values and the position can be restored with @PreserveOnRefresh.
  • Resize event needs to convey updated top/left coordinates as well.

rolfsmeds avatar Oct 07 '24 08:10 rolfsmeds

It is possible to set the position using JavaScript, example is found here

https://github.com/TatuLund/mdi-demo/blob/master/src/main/java/com/example/application/components/window/Window.java#L222

TatuLund avatar Oct 07 '24 09:10 TatuLund

One problem with that is that the dragging of the dialog element can behave unexpectedly if the size is not set on drag. Take, for instance, the example in the dev/dialog.html page in our repo:

https://github.com/user-attachments/assets/8ae492f1-2056-450c-ab6a-a12614df3747

We set max-width in the root element (root.style.maxWidth = '40em';) passed to the renderer (which, essentially, is the vaadin-dialog-overlayelement. As can be seen at the start of the recording, the size of the element is what restricts thepart=overlayelement to expand horizontally to fit its content. When the user drags the element, since only thetopandleft` properties are being defined, the element will grow when moved to the left and shrink when it is moved to the right (until the point it no longer can shrink and the whole element will move).

If, however, we add a container to the content elements and define a size for this container instead of the root element:

      const container = document.createElement('div');
      container.style.maxWidth = '40em';
      container.style.minWidth = '20em';
      root.appendChild(container);

      // Add elements to `container`
      // ...

https://github.com/user-attachments/assets/a41fbf91-bfe9-49d3-868d-a3bb62a4cd58

Then, the dragging will occur as expected with the change in the element shrinking when it moves to the right edge until it reaches its size limit.

DiegoCardoso avatar Oct 09 '24 11:10 DiegoCardoso

Closed as complete via https://github.com/vaadin/web-components/pull/7970, https://github.com/vaadin/web-components/pull/7971, https://github.com/vaadin/web-components/pull/8030, https://github.com/vaadin/web-components/pull/8047, https://github.com/vaadin/flow-components/pull/6782, https://github.com/vaadin/flow-components/pull/6783, and https://github.com/vaadin/flow-components/pull/6784.

DiegoCardoso avatar Nov 08 '24 14:11 DiegoCardoso