Skip to content

Commit a256d6c

Browse files
author
Akos Kitta
committed
Improved the scroll UX in list widgets
- Fixed scrollbar does not reach end of list widget. - Estimated row heights to provide better scroll UX. - Last item's `<select>` must be visible. Closes #1380 Closes #1381 Closes #1387 Signed-off-by: Akos Kitta <[email protected]>
1 parent 0d545be commit a256d6c

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

Diff for: arduino-ide-extension/src/browser/style/list-widget.css

-4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@
4444
height: 100%; /* This has top be 100% down to the `scrollContainer`. */
4545
}
4646

47-
.filterable-list-container .items-container {
48-
padding-bottom: calc(2 * var(--theia-statusBar-height));
49-
}
50-
5147
.filterable-list-container .items-container > div > div:nth-child(odd) {
5248
background-color: var(--theia-sideBar-background);
5349
filter: contrast(105%);

Diff for: arduino-ide-extension/src/browser/widgets/component-list/component-list-item.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class ComponentListItem<
3232
const { item, itemRenderer } = this.props;
3333
return (
3434
<div
35-
onMouseEnter={() => this.setState({ focus: true })}
35+
onMouseOver={() => this.setState({ focus: true })}
3636
onMouseLeave={() => this.setState({ focus: false })}
3737
>
3838
{itemRenderer.renderItem(

Diff for: arduino-ide-extension/src/browser/widgets/component-list/component-list.tsx

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'react-virtualized/styles.css';
12
import * as React from '@theia/core/shared/react';
23
import AutoSizer from 'react-virtualized/dist/commonjs/AutoSizer';
34
import {
@@ -43,7 +44,7 @@ export class ComponentList<T extends ArduinoComponent> extends React.Component<
4344
constructor(props: ComponentList.Props<T>) {
4445
super(props);
4546
this.cache = new CellMeasurerCache({
46-
defaultHeight: 300,
47+
defaultHeight: 140,
4748
fixedWidth: true,
4849
});
4950
}
@@ -59,14 +60,19 @@ export class ComponentList<T extends ArduinoComponent> extends React.Component<
5960
this.mostRecentWidth = width;
6061
return (
6162
<List
62-
className={'items-container'}
63+
className="items-container"
6364
rowRenderer={this.createItem}
6465
height={height}
6566
width={width}
6667
rowCount={this.props.items.length}
6768
rowHeight={this.cache.rowHeight}
6869
deferredMeasurementCache={this.cache}
6970
ref={this.setListRef}
71+
estimatedRowSize={140}
72+
// If default value, then `react-virtualized` will optimize and list item will not receive a `:hover` event.
73+
// Hence, install and version `<select>` won't be visible even if the mouse cursor is over the `<div>`.
74+
// See https://github.com/bvaughn/react-virtualized/blob/005be24a608add0344284053dae7633be86053b2/source/Grid/Grid.js#L38-L42
75+
scrollingResetTimeInterval={0}
7076
/>
7177
);
7278
}}
@@ -83,7 +89,7 @@ export class ComponentList<T extends ArduinoComponent> extends React.Component<
8389
}
8490
}
8591

86-
private setListRef = (ref: List | null): void => {
92+
private readonly setListRef = (ref: List | null): void => {
8793
this.list = ref || undefined;
8894
};
8995

@@ -101,14 +107,21 @@ export class ComponentList<T extends ArduinoComponent> extends React.Component<
101107
private clear(index: number): void {
102108
this.cache.clear(index, 0);
103109
this.list?.recomputeRowHeights(index);
104-
// Update the last item if the if the one before was updated
105-
if (index === this.props.items.length - 2) {
106-
this.cache.clear(index + 1, 0);
107-
this.list?.recomputeRowHeights(index + 1);
110+
// The last item need extra space height for the footer on hover.
111+
if (index === this.props.items.length - 1) {
112+
this.list?.recomputeGridSize();
113+
// Scroll to the very end if the last item has the :hover, so that footer will be visible.
114+
const endPosition = this.list?.getOffsetForRow({
115+
index,
116+
alignment: 'end',
117+
});
118+
if (endPosition) {
119+
this.list?.scrollToPosition(endPosition);
120+
}
108121
}
109122
}
110123

111-
private createItem: ListRowRenderer = ({
124+
private readonly createItem: ListRowRenderer = ({
112125
index,
113126
parent,
114127
key,

Diff for: arduino-ide-extension/src/browser/widgets/component-list/filterable-list-container.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ export class FilterableListContainer<
5151
<div className={'filterable-list-container'}>
5252
{this.renderSearchBar()}
5353
{this.renderSearchFilter()}
54-
{this.renderComponentList()}
54+
<div className="filterable-list-container">
55+
{this.renderComponentList()}
56+
</div>
5557
</div>
5658
);
5759
}

0 commit comments

Comments
 (0)