Comments (8)
This behavior is a known issue in the swing feature pair. You can verify it in the IDE: when a "LazyColumnLike" component (such as the project tree) gains focus, the first item is selected. This allows you to navigate freely using arrow keys. The same applies to SLC if you set a selection either through clicking or programmatically.
Why is the scenario of "selecting the first element" not desirable?
Unlike Swing, the lazy column is not fully loaded into memory, so it's possible that an element with key k is selected even if it's not currently in the visible range... In that case? should the list scroll or what? Other possible scenarios come to mind that would need to be addressed...
However, nothing prevents the user from setting the selected element by manipulating the state during the construction of the list!
It would also be possible to add the key of the first element to the set of selected items if it's empty, but this would result in losing support for "nothing selected."
Feel free to suggest any other solution!
from jewel.
I think Swing selects the first visible item, or the last selected item, when a list gains focus. We should do the same thing.
If the last selected item key doesn't exist anymore, I'd select the first visible one. I think that's what Swing does (but will double check). I agree with Yasser that focusing the component should allow you to keyboard navigate immediately
from jewel.
So, I checked and the Swing behaviour is as follows:
- When focusing a list, either the previous selection is kept, or the first item gets selected (if there is any item in the list)
- When the current selection is gone (e.g., item removed), the item above (i.e.,
selectedIndex - 1
) is selected - If the item was the first one, then the next one is selected (i.e., the selection remains on
selectedIndex
even if the item is now different) - If there are no items left, the selection is null
- The selection can only be null when the list is empty, or if it has never received focus before
On multi-select lists, it pretty much follows the same rules. The only difference is that when there are multiple items selected and one of them disappears, the item also disappears from the selection, but other selected items remain selected. If all selected items are removed, the behaviour is the same as for the single-select list.
We should align to this behaviour. If the list is empty when it receives focus, it'll have no selection, but as soon as the user uses the keyboard to move the selection, a selection is created on the first item. If apps want to create a selection once they add data to the list, they're free to do so, but we won't do it for them.
from jewel.
I agree with the proposed solution. Thanks for the investigation!
from jewel.
@fscarponi please look into this when you have time 🙏
from jewel.
Hi Folks,
there is not too much effort to get the desired result, except for point 2...
The current implementation of the data structure is not minded to store ordered keys, so I'm not sure if it is possible to achieve this behavior without rethinking the key management, we need to investigate deeper. (keep in mind that the SLC supports selectable AND not-selectable elements, such as the headers)
The problem is that I'm busy at the moment and can't provide an ETA. If you need this asap, I can try to discuss/schedule this task with my TL
from jewel.
@fscarponi The only thing on my end needed ASAP is the ability to tab into the selectableLazyColumn
and use arrow keys when there is no selection made before (the original problem). I say this because the Profiler needs to support full keybaord navigation; one of the major components on opening the UI is a selectableLazyColumn
, and the user cannot make their selection if they are purely using the keyboard. I am okay with the other behavior coming later if that is alright.
from jewel.
#372 add an hotfix for the point 1
When focusing a list, either the previous selection is kept, or the first item gets selected (if there is any item in the list)
to implement other behaviors is possible but requires more investigations, keeping this state easily savable and consistent.
I will take care to create a new issue for these features
from jewel.
Related Issues (20)
- LazyTree - How to add nodes after network call HOT 6
- Cannot navigate out of selectableLazyColumn using keyboard HOT 6
- Define a theme key/name
- Ensure theme name is used as key instead of isDark where appropriate
- Divider composable color is transparent in Intellij Classic UI's Darkula Theme
- MenuScope::separator doesn't seem to do anything HOT 1
- Stand-alone sample app crashes on progress indicator when switching themes HOT 1
- Dragging on the TitleBar to move the window does not always work HOT 5
- `Text` composable doesn't use color from TextStyle HOT 7
- Jewel theme text style is not applied in markdown blocks HOT 5
- No support for lazy loading of child's in LazyTree HOT 5
- Improve selection behaviours on SLC
- TooltipMetrics not initialised from LaF in the bridge
- Add GPG signatures to released artefacts HOT 1
- Soft new line in Blockquote shouldn't be interpreted as hard new line
- Package a standalone Compose App on Windows platform HOT 3
- Add API to syntax-highlight code
- Validate Jewel on IJP 242 EAPs
- Move main branch to 242
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jewel.