diff --git a/packages/core/src/components/tag-input/tagInput.tsx b/packages/core/src/components/tag-input/tagInput.tsx index 1bbae9f7b9..11092b6fe5 100644 --- a/packages/core/src/components/tag-input/tagInput.tsx +++ b/packages/core/src/components/tag-input/tagInput.tsx @@ -77,7 +77,7 @@ export interface ITagInputProps extends IntentProps, Props { inputProps?: HTMLInputProps; /** Ref handler for the `` element. */ - inputRef?: (input: HTMLInputElement | null) => void; + inputRef?: IRef; /** Controlled value of the `` element. This is shorthand for `inputProps={{ value }}`. */ inputValue?: string; diff --git a/packages/popover2/src/popover2.tsx b/packages/popover2/src/popover2.tsx index c8f40e58b7..6a698f0c8f 100644 --- a/packages/popover2/src/popover2.tsx +++ b/packages/popover2/src/popover2.tsx @@ -28,6 +28,7 @@ import { mergeRefs, Overlay, Utils, + IRef, } from "@blueprintjs/core"; import * as Classes from "./classes"; @@ -88,7 +89,7 @@ export interface IPopover2Props> extends P /** * Ref supplied to the `Classes.POPOVER` element. */ - popoverRef?: (ref: HTMLElement | null) => void; + popoverRef?: IRef; /** * Popper.js positioning strategy. diff --git a/packages/select/src/components/select/multiSelect.tsx b/packages/select/src/components/select/multiSelect.tsx index 3897b1b56f..db20c42545 100644 --- a/packages/select/src/components/select/multiSelect.tsx +++ b/packages/select/src/components/select/multiSelect.tsx @@ -28,6 +28,8 @@ import { Position, TagInput, TagInputAddMethod, + refHandler, + setRef, } from "@blueprintjs/core"; import { Classes, IListItemsProps } from "../../common"; @@ -113,18 +115,26 @@ export class MultiSelect extends AbstractPureComponent2, private TypedQueryList = QueryList.ofType(); - private input: HTMLInputElement | null = null; + public input: HTMLInputElement | null = null; - private queryList: QueryList | null = null; + public queryList: QueryList | null = null; - private refHandlers = { - input: (ref: HTMLInputElement | null) => { - this.input = ref; - this.props.tagInputProps?.inputRef?.(ref); - }, + private refHandlers: { + input: React.RefCallback; + queryList: React.RefCallback>; + } = { + input: refHandler(this, "input", this.props.tagInputProps?.inputRef), queryList: (ref: QueryList | null) => (this.queryList = ref), }; + public componentDidUpdate(prevProps: MultiSelectProps) { + if (prevProps.tagInputProps?.inputRef !== this.props.tagInputProps?.inputRef) { + setRef(prevProps.tagInputProps?.inputRef, null); + this.refHandlers.input = refHandler(this, "input", this.props.tagInputProps?.inputRef); + setRef(this.props.tagInputProps?.inputRef, this.input); + } + } + public render() { // omit props specific to this component, spread the rest. const { openOnKeyDown, popoverProps, tagInputProps, ...restProps } = this.props;