vaadin / flow-components

Java counterpart of Vaadin Web Components
100 stars 66 forks source link

Spreadsheet: Read-only and disabled behavior #6413

Open marcobsidian opened 2 months ago

marcobsidian commented 2 months ago

Description

Within our application, we want to use the Vaadin Spreadsheet as a File Preview for Excel Files.

These files shouldnt be editable, only viewable. We expected to achieve this by setting the "readOnly" or "enabled" -Properties of the Spreadsheet, similar to other components. Sadly, this does not work, as it currently results in this:

Setting a Spreadsheet to Read-Only (readOnly=true)

Setting a Spreadsheet to disabled (enabled=false)

We think this current behavior is flawed or at least very confusing and unituitive. We expected more of a "Pro-only" component.

Expected outcome

Setting a Spreadsheet to read-only achieves the following

Setting a Spreadsheet to disabled achieves the following

Minimal reproducible example

Paste this in any empty Vaadin View.

...
// Obviously tweak the Path to lead to any valid Excel-File with content :)
File myFile = new File("myFile.xlsx");

Spreadsheet viewer1 = new Spreadsheet(myFile);
viewer1.setReadOnly(true);

Spreadsheet viewer2 = new Spreadsheet(myFile);
viewer2.setEnabled(false);

add(viewer1, viewer2);
...

Steps to reproduce

Open a page that includes the Minimal reproducible example above

Environment

Vaadin version(s): 24.3 OS: Windows 11

Browsers

Chrome, Edge

DiegoCardoso commented 2 months ago

Hi @marcobsidian, I wasn't able to find the API you mentioned in the Spreadsheet component:

image image

I am afraid I am missing something here, could you provide more details, maybe a project with the reproducible code?

marcobsidian commented 2 months ago

Okay I double checked again and it is actually a hilarious error on my side.

For context: We are using Kotlin for our project. Also, we are using the Spreadsheet within our own CustomField. The initializer of the Spreadsheet looks like this:

Screenshot 2024-07-14 112928

None of us realised that the read-only assignment within the apply targeted the wrapping CustomField and not the Spreadsheet. ^^'

If i change the call to this.isReadOnly = true, it correctly gives me a compiler error.

marcobsidian commented 2 months ago

I was clearly wrong about this being a bug. The quality of Vaadin Pro Components is clearly better than the eyesight of me and my colleagues ^^'

However, while this isn't a bug, it would still be very helpful to have ways to disable interaction with the Spreadsheet component.

Our current "workaround" (see code pic above) isnt really doing it.

Are there any existing tools we overlooked to get a interactable, but not editable Excel Preview. If not, would it be possible to add something like this as an enhancement in close future?

tomivirkki commented 1 month ago

Hi,

After some investigation, I discovered that the Spreadsheet GWT widget does have some kind of a read-only state implementation, but for whatever reason it's not exposed publicly with the Spreadsheet component.

While there currently isn't a public read-only mode for the component, maybe as a workaround you could consider locking all the cells programmatically.