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

[Autocomplete] Use Popper with when disablePortal #23263

Merged
merged 3 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/src/pages/components/autocomplete/ComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import Autocomplete from '@material-ui/core/Autocomplete';
export default function ComboBox() {
return (
<Autocomplete
disablePortal
id="combo-box-demo"
options={top100Films}
style={{ width: 300 }}
renderInput={(params) => (
<TextField {...params} label="Combo box" variant="outlined" />
<TextField {...params} label="Movie" variant="outlined" />
)}
/>
);
Expand Down
3 changes: 2 additions & 1 deletion docs/src/pages/components/autocomplete/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import Autocomplete from '@material-ui/core/Autocomplete';
export default function ComboBox() {
return (
<Autocomplete
disablePortal
id="combo-box-demo"
options={top100Films}
style={{ width: 300 }}
renderInput={(params) => (
<TextField {...params} label="Combo box" variant="outlined" />
<TextField {...params} label="Movie" variant="outlined" />
)}
/>
);
Expand Down
11 changes: 2 additions & 9 deletions packages/material-ui/src/Autocomplete/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,6 @@ export const styles = (theme) => ({
},
});

function DisablePortal(props) {
// eslint-disable-next-line react/prop-types
const { anchorEl, open, ...other } = props;
return <div {...other} />;
}

const Autocomplete = React.forwardRef(function Autocomplete(props, ref) {
/* eslint-disable @typescript-eslint/no-unused-vars */
const {
Expand Down Expand Up @@ -314,7 +308,7 @@ const Autocomplete = React.forwardRef(function Autocomplete(props, ref) {
openText = 'Open',
options,
PaperComponent = Paper,
PopperComponent: PopperComponentProp = Popper,
PopperComponent = Popper,
popupIcon = <ArrowDropDownIcon />,
renderGroup: renderGroupProp,
renderInput,
Expand All @@ -327,8 +321,6 @@ const Autocomplete = React.forwardRef(function Autocomplete(props, ref) {
} = props;
/* eslint-enable @typescript-eslint/no-unused-vars */

const PopperComponent = disablePortal ? DisablePortal : PopperComponentProp;

const {
getRootProps,
getInputProps,
Expand Down Expand Up @@ -481,6 +473,7 @@ const Autocomplete = React.forwardRef(function Autocomplete(props, ref) {
className={clsx(classes.popper, {
[classes.popperDisablePortal]: disablePortal,
})}
disablePortal={disablePortal}
style={{
width: anchorEl ? anchorEl.clientWidth : null,
}}
Expand Down