-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ui-popover): add scrollbar to Popover if it is out of view #1885
base: master
Are you sure you want to change the base?
fix(ui-popover): add scrollbar to Popover if it is out of view #1885
Conversation
|
if (this._contentElement) { | ||
const rect = this._contentElement.getBoundingClientRect() | ||
const windowHeight = window.innerHeight | ||
return rect.bottom > windowHeight || rect.top < 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am using the ref for the displayed content and check whether it crosses the top or bottom side of the browser window.
@@ -272,6 +281,10 @@ class Popover extends Component<PopoverProps, PopoverState> { | |||
} | |||
} | |||
|
|||
if (this.isContentOutOfView()) { | |||
offsetY = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If part of the displayed content is offscreen, setting an offset for Y is pointless and it breaks the logic used in line 594.
@@ -578,7 +591,15 @@ class Popover extends Component<PopoverProps, PopoverState> { | |||
|
|||
return ( | |||
<ContextView {...viewProps} borderColor={styles?.borderColor}> | |||
{content} | |||
<div | |||
style={{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left this here instead of putting into the styles file because 1/ it contains logic, 2/ this is not purely styling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I use the test code below it first adds a scrollbar, but if I close and open the popover again it does not
class Example extends React.Component {
state = {
isShowingContent: false
}
renderCloseButton() {
return (
<CloseButton
placement="end"
offset="small"
onClick={() => this.setState({ isShowingContent: false })}
screenReaderLabel="Close"
/>
)
}
render() {
return (
<View>
<Popover
renderTrigger={<Button>Sign In</Button>}
isShowingContent={this.state.isShowingContent}
onShowContent={(e) => {
this.setState({ isShowingContent: true })
}}
onHideContent={(e, { documentClick }) => {
this.setState({ isShowingContent: false })
}}
on="click"
screenReaderLabel="Popover Dialog Example"
shouldContainFocus
shouldReturnFocus
shouldCloseOnDocumentClick
offsetY="16px"
>
<View padding="medium" display="block" as="form">
{this.renderCloseButton()}
<FormFieldGroup description="Log In">
<TextInput
renderLabel="Username"
inputRef={(el) => {
if (el) {
this._username = el
}
}}
/>
<TextInput renderLabel="Password" type="password" />
<TextInput renderLabel="Password" type="password" />
<TextInput renderLabel="Password" type="password" />
<TextInput renderLabel="Password" type="password" />
<TextInput renderLabel="Password" type="password" />
<TextInput renderLabel="Password" type="password" />
<TextInput renderLabel="Password" type="password" />
<TextInput renderLabel="Password" type="password" />
<TextInput renderLabel="Password" type="password" />
</FormFieldGroup>
</View>
</Popover>
</View>
)
}
}
render(<Example />)
isContentOutOfView() { | ||
if (this._contentElement) { | ||
const rect = this._contentElement.getBoundingClientRect() | ||
const windowHeight = window.innerHeight |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think trying to access window
with SSR will lead to a crash? Can you please use canUseDOM
and if its false this function could just return false
.
INSTUI-4453
Test 1
Test 2
The Popover being slightly off screen during zoom is not an issue according to Reka.