Skip to content

Commit

Permalink
[Autocomplete] Use Popper with when disablePortal (#23263)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored Nov 12, 2020
1 parent 96118a2 commit c1b3e33
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
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 @@ -313,7 +307,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 @@ -326,8 +320,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 @@ -480,6 +472,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

0 comments on commit c1b3e33

Please sign in to comment.