Skip to content
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: make picklist responsive for mobile when search is enabled #2519

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/components/Picklist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import InternalDropdown from '../InternalDropdown';
import InternalOverlay from '../InternalOverlay';
import WindowResize from '../../libs/WindowResize';

function positionResolver(opts) {
function positionResolver(opts, enableSearch) {
const { trigger, viewport, content } = opts;
const newOpts = {
trigger,
Expand All @@ -30,6 +30,13 @@ function positionResolver(opts) {
width: trigger.width,
},
};
if (enableSearch && viewport.width <= 600) {
return {
top: 0,
left: 0,
width: viewport.width,
};
}
return {
...InternalOverlay.defaultPositionResolver(newOpts),
width: trigger.width,
Expand Down Expand Up @@ -82,7 +89,9 @@ class Picklist extends Component {
this.handleBlur();
}
});
this.windowScrolling.startListening(this.handleWindowScroll);
if (window.screen.width > 600) {
this.windowScrolling.startListening(this.handleWindowScroll);
}
this.windowResize.startListening(this.handleWindowResize);
}
}
Expand Down Expand Up @@ -298,9 +307,10 @@ class Picklist extends Component {
/>
<InternalOverlay
isVisible={isOpen}
positionResolver={positionResolver}
positionResolver={opt => positionResolver(opt, enableSearch)}
onOpened={() => this.dropdownRef.current.focus()}
triggerElementRef={() => this.triggerRef}
keepScrollEnabled
>
<InternalDropdown
id={this.listboxId}
Expand Down