From 2bc2726d469ad4842ce8db18303f99096ae4a377 Mon Sep 17 00:00:00 2001 From: atzcl Date: Tue, 17 Nov 2020 16:11:35 +0800 Subject: [PATCH] feat: mount scrollTo on ref --- src/Selector/index.tsx | 2 ++ src/generate.tsx | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/Selector/index.tsx b/src/Selector/index.tsx index f9fb9a9f1..8466c44cd 100644 --- a/src/Selector/index.tsx +++ b/src/Selector/index.tsx @@ -11,6 +11,7 @@ import * as React from 'react'; import { useRef } from 'react'; import KeyCode from 'rc-util/lib/KeyCode'; +import { ScrollTo } from 'rc-virtual-list/lib/List'; import MultipleSelector from './MultipleSelector'; import SingleSelector from './SingleSelector'; import { LabelValueType, RawValueType, CustomTagProps } from '../interface/generator'; @@ -45,6 +46,7 @@ export interface InnerSelectorProps { export interface RefSelectorProps { focus: () => void; blur: () => void; + scrollTo?: ScrollTo, } export interface SelectorProps { diff --git a/src/generate.tsx b/src/generate.tsx index e4bd8023b..183c8e943 100644 --- a/src/generate.tsx +++ b/src/generate.tsx @@ -12,6 +12,7 @@ import { useState, useRef, useEffect, useMemo } from 'react'; import KeyCode from 'rc-util/lib/KeyCode'; import classNames from 'classnames'; import useMergedState from 'rc-util/lib/hooks/useMergedState'; +import { ScrollTo } from 'rc-virtual-list/lib/List'; import Selector, { RefSelectorProps } from './Selector'; import SelectTrigger, { RefTriggerProps } from './SelectTrigger'; import { RenderNode, Mode, RenderDOMFunc, OnActiveValue } from './interface'; @@ -57,6 +58,7 @@ const DEFAULT_OMIT_PROPS = [ export interface RefSelectProps { focus: () => void; blur: () => void; + scrollTo?: ScrollTo, } export interface SelectProps extends React.AriaAttributes { @@ -365,6 +367,7 @@ export default function generateSelector< React.useImperativeHandle(ref, () => ({ focus: selectorRef.current.focus, blur: selectorRef.current.blur, + scrollTo: listRef.current?.scrollTo, })); // ============================= Value ==============================