Skip to content

Commit

Permalink
feat(NestedSelect): Rerender BottomSheet if content change
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed Oct 18, 2023
1 parent c93efb2 commit b26e6bd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 8 additions & 2 deletions react/NestedSelect/BottomSheet.jsx
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useState } from 'react'
import cx from 'classnames'

import Icon from '../Icon'
Expand Down Expand Up @@ -31,10 +31,16 @@ const HeaderComponent = ({ title, showBack, onClickBack }) => {
}

const SelfBottomSheet = props => {
const [, setInnerContentHeight] = useState(0) // tricks to rerender BottomSheet

return (
<BottomSheet backdrop onClose={props.onClose}>
<BottomSheetItem disableGutters>
<NestedSelect HeaderComponent={HeaderComponent} {...props} />
<NestedSelect
HeaderComponent={HeaderComponent}
setInnerContentHeight={setInnerContentHeight}
{...props}
/>
</BottomSheetItem>
</BottomSheet>
)
Expand Down
11 changes: 9 additions & 2 deletions react/NestedSelect/NestedSelect.jsx
Expand Up @@ -18,6 +18,7 @@ export { ItemRow }
class NestedSelect extends Component {
constructor(props) {
super(props)
this.innerRef = React.createRef()
this.state = {
history: [props.options],
searchValue: '',
Expand All @@ -29,6 +30,12 @@ class NestedSelect extends Component {
this.unmounted = true
}

componentDidUpdate() {
const { setInnerContentHeight } = this.props

setInnerContentHeight?.(this.innerRef?.current?.offsetHeight)
}

resetHistory() {
if (this.unmounted) {
return
Expand Down Expand Up @@ -105,7 +112,7 @@ class NestedSelect extends Component {
}

return (
<>
<span ref={this.innerRef}>
{HeaderComponent ? (
<HeaderComponent
title={current.title || title}
Expand Down Expand Up @@ -171,7 +178,7 @@ class NestedSelect extends Component {
))
)}
</ContentComponent>
</>
</span>
)
}
}
Expand Down

0 comments on commit b26e6bd

Please sign in to comment.