How do I remove the border from a spreadsheet?
I tried adding this to main-layout.css:
div .v-spreadsheet {
border: 0 !important;
}
How do I remove the border from a spreadsheet?
I tried adding this to main-layout.css:
div .v-spreadsheet {
border: 0 !important;
}
The respective div is part of the shadow dom and thus not accessible via ânormalâ css. Unfortunately it neither has a part attribute, therefore you will have to use shadow dom styling.
In this case, you need to create a file âvaadin-spreadsheet.cssâ inside the folder structure âyour-theme/components/â. This will then be applied to the shadow dom styling of the spreadsheet. For more details, check the documentation.
.../frontend/themes/your-theme/components/vaadin-spreadsheet.css
div .v-spreadsheet {
border: 0 none; /*no !important necessary*/
}
Thanks, but I still canât make it work, I have a feeling there is a step missing, but I canât see what it is.
I have tried with a
frontend\themes\my-spreadsheet-app\components\vaadin-spreadsheet.css
containing different CSS like these:
div .v-spreadsheet {
border: 0;
}
and after doing a
spreadsheet.addClassName(âno-borderâ);
that showed up in the browsers debugger as
<vaadin-spreadsheet class=âhidefunctionbar hidetabsheet no-borderâ ⌠>
I tried this, with and without the div
:host(.no-border) div .v-spreadsheet {
border: 0 !important;
}
Following the documentation to Disable Pre-Compiled Frontend Bundle
I have added both
vaadin.frontend.hotdeploy=true
to application.properties
and
< build>
<defaultGoal>spring-boot:run</defaultGoal>
<plugins>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<version>${vaadin.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-frontend</goal>
</goals>
</execution>
</executions>
<configuration>
<frontendHotdeploy>true</frontendHotdeploy>
</configuration>
</plugin>
</plugins>
</build>
to pom.xml
finally I have checked that I get a file like this to apply the vaadin-spreadsheet.css
frontend\generated\theme-my-spreadsheet-app.components.generated.js
with this content:
import { unsafeCSS, registerStyles } from â@vaadin/vaadin-themable-mixin/register-stylesâ;
import vaadinSpreadsheetCss from âthemes/my-spreadsheet-app/components/vaadin-spreadsheet.css?inlineâ;
if (!document[â_vaadintheme_my-spreadsheet-app_componentCssâ]) {
registerStyles(
âvaadin-spreadsheetâ,
unsafeCSS(vaadinSpreadsheetCss.toString())
);
document[â_vaadintheme_my-spreadsheet-app_componentCssâ] = true;
}
if (import.meta.hot) {
import.meta.hot.accept((module) => {
window.location.reload();
});
}
Console output
I get this in the console confirming the above:
: Started Vite. Time: 1423ms
: â Local: http://127.0.0.1:52885/VAADIN/
: Application running at http://localhost:8090/
:
: [TypeScript] Found 0 errors. Watching for file changes.
: 20.18.53 [vite] (client) hmr update /generated/theme-my-spreadsheet-app.components.generated.js
Unfortunatelly this does not work as vaadin-spreadsheet does not implement ThemableMixin.
See https://vaadin.com/docs/latest/components/spreadsheet#limitations
âNo support for theming the component the same way as other Vaadin components.â
Currently the best way to customize the Spreadsheet looks is to set it to Lumo theme mode and use Lumo CSS variables to customize. However I am not sure if it is possible to disable just the outer border with that, but you can try.
Yeah no unfortunately the approach proposed by @Stefan.27 wonât work, because the Spreadsheet component doesnât support shadow DOM CSS injection, unlike other Vaadin components.
And it also doesnât expose part names like other Vaadin components.
(The docs express this rather vaguely as âNo support for theming the component the same way as other Vaadin components.â)
So unfortunately itâs a bit awkward as youâll need to handle the injection of css into the shdow dom âmanuallyâ, like so:
Element element = new Element("style");
element.setText("""
.v-spreadsheet {
border: none;
}
""");
spreadsheet.getElement().appendVirtualChild(element);
spreadsheet.getElement().executeJs("this.shadowRoot.appendChild($0)", element);
(Note that the selector you tried to use is also incorrect as it matches a classname v-spreadsheet
inside a div
, rather than a div
with the classname v-spreadsheet
)
Thanks
It works now.
I had to add !important to Rolf 's code to avoid it being overwritten by the standard
v-spreadsheet class.
Good point about the CSS selector.
Vaadin surely is a great product.
Happy new year