mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-27 10:35:23 +01:00
Scroll selected <LayerListItem/> into view
This commit is contained in:
parent
fcfc7ab874
commit
fcad636f85
1 changed files with 22 additions and 5 deletions
|
@ -42,11 +42,15 @@ class LayerListContainer extends React.Component {
|
||||||
onLayerSelect: () => {},
|
onLayerSelect: () => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
state = {
|
constructor(props) {
|
||||||
collapsedGroups: {},
|
super(props);
|
||||||
areAllGroupsExpanded: false,
|
this.selectedItemRef = React.createRef();
|
||||||
isOpen: {
|
this.state = {
|
||||||
add: false,
|
collapsedGroups: {},
|
||||||
|
areAllGroupsExpanded: false,
|
||||||
|
isOpen: {
|
||||||
|
add: false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,6 +165,13 @@ class LayerListContainer extends React.Component {
|
||||||
return propsChanged;
|
return propsChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidUpdate () {
|
||||||
|
const selectedItemNode = this.selectedItemRef.current;
|
||||||
|
if (selectedItemNode && selectedItemNode.node) {
|
||||||
|
selectedItemNode.node.scrollIntoView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
||||||
const listItems = []
|
const listItems = []
|
||||||
|
@ -189,6 +200,11 @@ class LayerListContainer extends React.Component {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const additionalProps = {};
|
||||||
|
if (idx === this.props.selectedLayerIndex) {
|
||||||
|
additionalProps.ref = this.selectedItemRef;
|
||||||
|
}
|
||||||
|
|
||||||
const listItem = <LayerListItem
|
const listItem = <LayerListItem
|
||||||
className={classnames({
|
className={classnames({
|
||||||
'maputnik-layer-list-item-collapsed': layers.length > 1 && this.isCollapsed(groupPrefix, groupIdx) && idx !== this.props.selectedLayerIndex,
|
'maputnik-layer-list-item-collapsed': layers.length > 1 && this.isCollapsed(groupPrefix, groupIdx) && idx !== this.props.selectedLayerIndex,
|
||||||
|
@ -205,6 +221,7 @@ class LayerListContainer extends React.Component {
|
||||||
onLayerDestroy={this.props.onLayerDestroy.bind(this)}
|
onLayerDestroy={this.props.onLayerDestroy.bind(this)}
|
||||||
onLayerCopy={this.props.onLayerCopy.bind(this)}
|
onLayerCopy={this.props.onLayerCopy.bind(this)}
|
||||||
onLayerVisibilityToggle={this.props.onLayerVisibilityToggle.bind(this)}
|
onLayerVisibilityToggle={this.props.onLayerVisibilityToggle.bind(this)}
|
||||||
|
{...additionalProps}
|
||||||
/>
|
/>
|
||||||
listItems.push(listItem)
|
listItems.push(listItem)
|
||||||
idx += 1
|
idx += 1
|
||||||
|
|
Loading…
Reference in a new issue