diff --git a/docs/pages/api/autocomplete.md b/docs/pages/api/autocomplete.md index 3b98615f021a0d..88ab04054a77b6 100644 --- a/docs/pages/api/autocomplete.md +++ b/docs/pages/api/autocomplete.md @@ -36,6 +36,7 @@ You can learn more about the difference by [reading this guide](/guides/minimizi | disabled | bool | false | If `true`, the input will be disabled. | | disableListWrap | bool | false | If `true`, the list box in the popup will not wrap focus. | | disableOpenOnFocus | bool | false | If `true`, the popup won't open on input focus. | +| disablePortal | bool | false | Disable the portal behavior. The children stay within it's parent DOM hierarchy. | | filterOptions | func | | A filter function that determines the options that are eligible.

**Signature:**
`function(options: undefined, state: object) => undefined`
*options:* The options to render.
*state:* The state of the component. | | filterSelectedOptions | bool | false | If `true`, hide the selected options from the list box. | | freeSolo | bool | false | If `true`, the Autocomplete is free solo, meaning that the user input is not bound to provided options. | @@ -55,12 +56,12 @@ You can learn more about the difference by [reading this guide](/guides/minimizi | open | bool | | Control the popup` open state. | | options | array | [] | Array of options. | | PaperComponent | elementType | Paper | The component used to render the body of the popup. | -| PopupComponent | elementType | Popper | The component used to render the popup. | +| PopperComponent | elementType | Popper | The component used to position the popup. | | renderGroup | func | | Render the group.

**Signature:**
`function(option: any) => ReactNode`
*option:* The group to render. | | renderInput * | func | | Render the input.

**Signature:**
`function(params: object) => ReactNode`
*params:* null | | renderOption | func | | Render the option, use `getOptionLabel` by default.

**Signature:**
`function(option: any, state: object) => ReactNode`
*option:* The option to render.
*state:* The state of the component. | | renderTags | func | | Render the selected value.

**Signature:**
`function(value: any) => ReactNode`
*value:* The `value` provided to the component. | -| value | any | | The input value. | +| value | any | | The value of the autocomplete. | The `ref` is forwarded to the root element. @@ -83,7 +84,8 @@ Any other props supplied will be provided to the root element (native element). | clearIndicatorDirty | .MuiAutocomplete-clearIndicatorDirty | Styles applied to the clear indictator if the input is dirty. | popupIndicator | .MuiAutocomplete-popupIndicator | Styles applied to the popup indictator. | popupIndicatorOpen | .MuiAutocomplete-popupIndicatorOpen | Styles applied to the popup indictator if the popup is open. -| popup | .MuiAutocomplete-popup | Styles applied to the popup element. +| popper | .MuiAutocomplete-popper | Styles applied to the popper element. +| popperDisablePortal | .MuiAutocomplete-popperDisablePortal | Styles applied to the popper element if `disablePortal={true}`. | paper | .MuiAutocomplete-paper | Styles applied to the `Paper` component. | listbox | .MuiAutocomplete-listbox | Styles applied to the `listbox` component. | loading | .MuiAutocomplete-loading | Styles applied to the loading wrapper. diff --git a/docs/src/pages/components/autocomplete/GitHubLabel.js b/docs/src/pages/components/autocomplete/GitHubLabel.js index 0f94ddaeee1c8c..3c1544201fe50b 100644 --- a/docs/src/pages/components/autocomplete/GitHubLabel.js +++ b/docs/src/pages/components/autocomplete/GitHubLabel.js @@ -1,6 +1,5 @@ /* eslint-disable no-use-before-define */ import React from 'react'; -import PropTypes from 'prop-types'; import { useTheme, fade, makeStyles } from '@material-ui/core/styles'; import Popper from '@material-ui/core/Popper'; import SettingsIcon from '@material-ui/icons/Settings'; @@ -10,23 +9,6 @@ import Autocomplete from '@material-ui/lab/Autocomplete'; import ButtonBase from '@material-ui/core/ButtonBase'; import InputBase from '@material-ui/core/InputBase'; -function Popup(props) { - const { popperRef, anchorEl, open, ...other } = props; - return
; -} - -Popup.propTypes = { - anchorEl: PropTypes.object, - open: PropTypes.bool.isRequired, - popperRef: PropTypes.oneOfType([ - PropTypes.oneOf([null]), - PropTypes.func, - PropTypes.shape({ - current: PropTypes.any.isRequired, - }), - ]).isRequired, -}; - const useStyles = makeStyles(theme => ({ root: { width: 221, @@ -201,7 +183,7 @@ export default function GitHubLabel() { setPendingValue(newValue); }} disableCloseOnSelect - PopupComponent={Popup} + disablePortal renderTags={() => null} noOptionsText="No labels" renderOption={(option, { selected }) => ( diff --git a/docs/src/pages/components/autocomplete/GitHubLabel.tsx b/docs/src/pages/components/autocomplete/GitHubLabel.tsx index 1d584814bed6b6..240c4d70c7a6c7 100644 --- a/docs/src/pages/components/autocomplete/GitHubLabel.tsx +++ b/docs/src/pages/components/autocomplete/GitHubLabel.tsx @@ -5,15 +5,10 @@ import Popper from '@material-ui/core/Popper'; import SettingsIcon from '@material-ui/icons/Settings'; import CloseIcon from '@material-ui/icons/Close'; import DoneIcon from '@material-ui/icons/Done'; -import Autocomplete, { PopupProps } from '@material-ui/lab/Autocomplete'; +import Autocomplete from '@material-ui/lab/Autocomplete'; import ButtonBase from '@material-ui/core/ButtonBase'; import InputBase from '@material-ui/core/InputBase'; -function Popup(props: PopupProps) { - const { popperRef, anchorEl, open, ...other } = props; - return
; -} - const useStyles = makeStyles((theme: Theme) => createStyles({ root: { @@ -190,7 +185,7 @@ export default function GitHubLabel() { setPendingValue(newValue); }} disableCloseOnSelect - PopupComponent={Popup} + disablePortal renderTags={() => null} noOptionsText="No labels" renderOption={(option: LabelType, { selected }) => ( diff --git a/docs/src/pages/components/autocomplete/Playground.js b/docs/src/pages/components/autocomplete/Playground.js index 405ef7802afc9a..76d671b3428e98 100644 --- a/docs/src/pages/components/autocomplete/Playground.js +++ b/docs/src/pages/components/autocomplete/Playground.js @@ -105,6 +105,13 @@ export default function Playground() { disabled renderInput={params => } /> + ( + + )} + />
); } diff --git a/docs/src/pages/components/autocomplete/Playground.tsx b/docs/src/pages/components/autocomplete/Playground.tsx index 785e960b84417c..f3f147dfc264c2 100644 --- a/docs/src/pages/components/autocomplete/Playground.tsx +++ b/docs/src/pages/components/autocomplete/Playground.tsx @@ -103,6 +103,13 @@ export default function Playground() { disabled renderInput={params => } /> + ( + + )} + />
); } diff --git a/docs/src/pages/components/autocomplete/UseAutocomplete.js b/docs/src/pages/components/autocomplete/UseAutocomplete.js index 4c6e7aa92994ec..f58a7c51ee85b3 100644 --- a/docs/src/pages/components/autocomplete/UseAutocomplete.js +++ b/docs/src/pages/components/autocomplete/UseAutocomplete.js @@ -4,6 +4,9 @@ import useAutocomplete from '@material-ui/lab/useAutocomplete'; import { makeStyles } from '@material-ui/core/styles'; const useStyles = makeStyles(theme => ({ + root: { + position: 'relative', + }, input: { width: 200, }, @@ -32,7 +35,7 @@ const useStyles = makeStyles(theme => ({ export default function UseAutocomplete() { const classes = useStyles(); const { - getRootProps, + getComboboxProps, getInputProps, getInputLabelProps, getListboxProps, @@ -44,10 +47,12 @@ export default function UseAutocomplete() { }); return ( -
- -
- +
+
+ +
+ +
{groupedOptions.length > 0 ? (