mirror of
https://github.com/maputnik/editor.git
synced 2026-08-24 14:07:33 +00:00
Merge pull request #639 from orangemug/fix/only-scroll-layer-list-if-item-not-in-view
Only scroll to selected item in <LayerList/> if not already in view.
This commit is contained in:
@@ -26,9 +26,7 @@ class AppLayout extends React.Component {
|
|||||||
return <div className="maputnik-layout">
|
return <div className="maputnik-layout">
|
||||||
{this.props.toolbar}
|
{this.props.toolbar}
|
||||||
<div className="maputnik-layout-list">
|
<div className="maputnik-layout-list">
|
||||||
<ScrollContainer>
|
{this.props.layerList}
|
||||||
{this.props.layerList}
|
|
||||||
</ScrollContainer>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="maputnik-layout-drawer">
|
<div className="maputnik-layout-drawer">
|
||||||
<ScrollContainer>
|
<ScrollContainer>
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ class LayerListContainer extends React.Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.selectedItemRef = React.createRef();
|
this.selectedItemRef = React.createRef();
|
||||||
|
this.scrollContainerRef = React.createRef();
|
||||||
this.state = {
|
this.state = {
|
||||||
collapsedGroups: {},
|
collapsedGroups: {},
|
||||||
areAllGroupsExpanded: false,
|
areAllGroupsExpanded: false,
|
||||||
@@ -169,7 +170,19 @@ class LayerListContainer extends React.Component {
|
|||||||
if (prevProps.selectedLayerIndex !== this.props.selectedLayerIndex) {
|
if (prevProps.selectedLayerIndex !== this.props.selectedLayerIndex) {
|
||||||
const selectedItemNode = this.selectedItemRef.current;
|
const selectedItemNode = this.selectedItemRef.current;
|
||||||
if (selectedItemNode && selectedItemNode.node) {
|
if (selectedItemNode && selectedItemNode.node) {
|
||||||
selectedItemNode.node.scrollIntoView();
|
const target = selectedItemNode.node;
|
||||||
|
const options = {
|
||||||
|
root: this.scrollContainerRef.current,
|
||||||
|
threshold: 1.0
|
||||||
|
}
|
||||||
|
const observer = new IntersectionObserver(entries => {
|
||||||
|
observer.unobserve(target);
|
||||||
|
if (entries.length > 0 && entries[0].intersectionRatio < 1) {
|
||||||
|
target.scrollIntoView();
|
||||||
|
}
|
||||||
|
}, options);
|
||||||
|
|
||||||
|
observer.observe(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -238,7 +251,7 @@ class LayerListContainer extends React.Component {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
return <div className="maputnik-layer-list">
|
return <div className="maputnik-layer-list" ref={this.scrollContainerRef}>
|
||||||
<AddModal
|
<AddModal
|
||||||
layers={this.props.layers}
|
layers={this.props.layers}
|
||||||
sources={this.props.sources}
|
sources={this.props.sources}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
// LAYER LIST
|
// LAYER LIST
|
||||||
.maputnik-layer-list {
|
.maputnik-layer-list {
|
||||||
|
height: 100%;
|
||||||
|
overflow: auto;
|
||||||
|
|
||||||
&-header {
|
&-header {
|
||||||
padding: $margin-2 $margin-2 $margin-3;
|
padding: $margin-2 $margin-2 $margin-3;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user