diff --git a/docs/pages/components/index.js b/docs/pages/components/index.js index ba613d5e1a..e7ef490d7b 100644 --- a/docs/pages/components/index.js +++ b/docs/pages/components/index.js @@ -53,6 +53,16 @@ export default function Components() { property. These components are given all the current props and state letting you achieve anything you dream up. + ## Inner Ref + Some components also take an innerRef prop that react-select needs in + order to manage internal behaviour. Please assign this to the ref + property of the relevant react-element. For example: + + ~~~~ + const CustomOption = ({ innerRef, innerProps }) => ( +
) + ~~~~ + ### Inner Props All functional properties that the component needs are provided in diff --git a/docs/pages/props/index.js b/docs/pages/props/index.js index 980e1d4e67..699bea114d 100644 --- a/docs/pages/props/index.js +++ b/docs/pages/props/index.js @@ -112,6 +112,17 @@ export default function Api() { letting you achieve anything you dream up. For more information in replacing components see [the components documentation](/components) + ### Inner Ref + Some components are passed an innerRef property to facilitate for internally + managed behaviour within the base select. This should be assigned to the + ref property of the relevant dom element. + i.e. + + ~~~ + const CustomOptionComponent = ({ innerProps, innerRef }) => + (
) + ~~~ + ### Inner Props All functional properties that the component needs are provided in diff --git a/docs/pages/upgradeGuide/index.js b/docs/pages/upgradeGuide/index.js index 5480de0b94..8ffd6eeb95 100644 --- a/docs/pages/upgradeGuide/index.js +++ b/docs/pages/upgradeGuide/index.js @@ -195,7 +195,7 @@ For example, to render a custom \`Option\` component: ~~~js components={{ Option: ({ children, innerProps }) => ( -
+
{children}
) @@ -213,8 +213,12 @@ understand are: * \`getStyles\` - a function that will return an object containing the styles for the component. If you have specified custom style modifiers, they will be executed by this function. +* \`innerRef\` - additional some components need to expose a ref to + the base Select component, to facilitate internally managed behaviour. + We specify this as innerRef to avoid collision with React's reserved \`ref\` + keyword when we spread props. -You don't _have_ to use these props, and are free to implement whatever - but +Aside from innerRef (where applicable), you don't _have_ to use these props, and are free to implement whatever - but they are intended to help make custom implementations easier to manage. See the [Components Documentation](/components) for more details and diff --git a/src/Select.js b/src/Select.js index dc8724693c..793ad60b51 100644 --- a/src/Select.js +++ b/src/Select.js @@ -1537,7 +1537,7 @@ export default class Select extends Component { // for performance, the menu options in state aren't changed when the // focused option changes so we calculate additional props based on that const isFocused = focusedOption === props.data; - props.innerProps.innerRef = isFocused + props.innerRef = isFocused ? this.getFocusedOptionRef : undefined; @@ -1606,9 +1606,7 @@ export default class Select extends Component { @@ -1706,8 +1704,8 @@ export default class Select extends Component { {this.renderLiveRegion()} , /** The mouse down event and the innerRef to pass down to the controller element. */ innerProps: { onMouseDown: (SyntheticMouseEvent) => void, - innerRef: ElementRef<*>, }, }; @@ -51,8 +51,7 @@ export const css = ({ isDisabled, isFocused }: State) => ({ }); const Control = (props: ControlProps) => { - const { children, cx, getStyles, className, isDisabled, isFocused, innerProps } = props; - const { innerRef, ...rest } = innerProps; + const { children, cx, getStyles, className, isDisabled, isFocused, innerRef, innerProps } = props; return (
{ 'control--is-disabled': isDisabled, 'control--is-focused': isFocused }, className)} - {...rest} + {...innerProps} > {children}
diff --git a/src/components/Menu.js b/src/components/Menu.js index 1f0f138967..9a763592ad 100644 --- a/src/components/Menu.js +++ b/src/components/Menu.js @@ -319,7 +319,7 @@ export type MenuListProps = { /** The children to be rendered. */ children: Node, /** Inner ref to DOM Node */ - innerProps: { innerRef: InnerRef }, + innerRef: InnerRef, }; export type MenuListComponentProps = CommonProps & MenuListProps & @@ -333,8 +333,7 @@ export const menuListCSS = ({ maxHeight }: MenuState) => ({ WebkitOverflowScrolling: 'touch', }); export const MenuList = (props: MenuListComponentProps) => { - const { children, className, cx, getStyles, isMulti, innerProps } = props; - const { innerRef } = innerProps; + const { children, className, cx, getStyles, isMulti, innerRef } = props; return (
({ }); const Option = (props: OptionProps) => { - const { children, className, cx, getStyles, isDisabled, isFocused, isSelected, innerProps } = props; - const { innerRef, ...rest } = innerProps; + const { children, className, cx, getStyles, isDisabled, isFocused, isSelected, innerRef, innerProps } = props; return (
{ }, className )} - {...rest} + {...innerProps} > {children}