我正在使用material UI
和react-sticky
及其工作的好,但我有一个问题。 https://codesandbox.io/s/xv41xzvyp我已经分享了我的尝试。重现的步骤
StickyContainer
组件有一个属性node
,它是容器最顶层元素的引用,因此您可以借助自己的引用将其滚动到视图中:
class CustomizedTabs extends React.Component {
ref = React.createRef();
state = {
value: 0
};
handleChange = (event, value) => {
this.setState({ value }, () => this.ref.current.node.scrollIntoView());
};
render() {
const { classes } = this.props;
const { value } = this.state;
return (
<div className={classes.root}>
<StickyContainer ref={this.ref}>{/* ... */}</StickyContainer>
</div>
);
}
}