Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: mark full size components with data attribute #20929

Merged
merged 7 commits into from
Jan 31, 2025

Conversation

sissbruecker
Copy link
Contributor

Description

Adds data attributes to components that have been configured to use the full size in a layout, by either calling setWidthFull, setHeightFull or setSizeFull. Vaadin components such as HorizontalLayout and VerticalLayout will include additional styles targeting children with these data attributes, to effectively make these children take up the remaining space in a layout, rather than the full size.

For now, the respective styles will only be added by the Vaadin components if the com.vaadin.experimental.layoutImprovements feature flag is enabled (see vaadin/web-components#8552).

Part of vaadin/flow-components#6998

Type of change

  • Feature

Copy link

github-actions bot commented Jan 29, 2025

Test Results

1 165 files  ± 0  1 165 suites  ±0   1h 38m 33s ⏱️ + 2m 5s
7 633 tests + 7  7 577 ✅ + 7  56 💤 ±0  0 ❌ ±0 
7 928 runs   - 35  7 865 ✅  - 33  63 💤  - 2  0 ❌ ±0 

Results for commit 54f023f. ± Comparison against base commit 355bfc2.

♻️ This comment has been updated with latest results.

@sissbruecker
Copy link
Contributor Author

@mshabarov I've dropped the v- from the attribute name.

@@ -47,6 +47,7 @@ public interface HasSize extends HasElement {
*/
default void setWidth(String width) {
getElement().getStyle().setWidth(width);
getElement().removeAttribute("data-width-full");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would leave a small gap which is when you call getElement().getStyle().setWidth() instead (add-ons may use this), you'll not get this attribute removed.

I was thinking of adding removeAttribute to the getElement().getStyle().setWidth(), but there is no direct access to the Element API. However, we can check if this is an Element, case and call this method.

What do you think, does it worth it or we can make an assumption that component's method would be sufficient for most of the usages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did take a look at Style and the probably relevant BasicElementStyle subclass, but am not sure how get a reference to the element from there.

In general I would assume that:

  • Users would usually use HasSize consistently
  • Probably not switch between full size and custom size that often

For now I would probably go with what we have. If this turns out to be a problem we have another option of changing the CSS selector in the web components to check for both, the data attribute and style="width: 100%" / style="height: 100%".

@@ -194,6 +195,7 @@ default Optional<Unit> getWidthUnit() {
*/
default void setHeight(String height) {
getElement().getStyle().setHeight(height);
getElement().removeAttribute("data-height-full");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we place these constants to Constants ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you have a better idea what kind of constants that class should contain. I think it wasn't too bad with just a few duplicates and covering those with unit tests. But I've extracted the attributes into constants for now.

Comment on lines 354 to 355
getElement().setAttribute("data-width-full", true);
getElement().setAttribute("data-height-full", true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it better to just call

setWidthFull();
setHeightFull();

where these attributes are already added?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, done.

@mshabarov mshabarov merged commit 4b321c7 into main Jan 31, 2025
26 checks passed
@mshabarov mshabarov deleted the feat/has-size-data-attributes branch January 31, 2025 10:45
@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with Vaadin 24.7.0.alpha7 and is also targeting the upcoming stable 24.7.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants