【发布时间】:2021-02-08 13:57:52
【问题描述】:
在 SPFX (SPO) webpart 中,我有 2 个按钮可以更改模态表单上的页面。
每次呈现下一页时,我都希望它滚动到顶部。
我正在尝试为 MS Fluent UI 模式分配一个 ID,但不能。如果我能做到这一点,那么我确定我可以使用element.scrollTo() 等。
这是模态:
<Modal
titleAriaId={this._titleId}
subtitleAriaId={this._subtitleId}
isOpen={this.state.showModal}
onDismiss={this._closeModal}
closeButtonAriaLabel={"Close"}
isBlocking={true}
containerClassName={this.state.ReduceSize}
id={'modal') //it doesn't accept this!
>
<div id={'top'} ... />
我还尝试为每个页面使用 'top' 的 id 标签,并尝试在单击下一页按钮时使用类似的内容:
var el = document.getElementById('top');
console.log(el); //This gets the correct id and displays the className details. But how can I scroll to it?
el.scrollTo() //or whatever should work because this doesn't.
我已阅读 https://reactjs.org/docs/refs-and-the-dom.html 的文档和
https://developer.microsoft.com/en-us/fluentui#/controls/web/modal#IModal 在后者中,我特别注意了 componentRef 属性,它可以保存答案,但由于没有示例而对如何使用一无所知。
需要一些帮助。
【问题讨论】:
标签: reactjs modal-dialog spfx