select组件结合anchor实现自由定位

如何实现select里自由滚动定位呢?

可以结合anchor组件实现。

代码如下

import React from 'react';
import 'antd/dist/antd.css';
import './index.css';
import { Select, Anchor } from 'antd';
const { Option, OptGroup } = Select;
const { Link } = Anchor;

const handleChange = (value) => {
  console.log(`selected ${value}`);
};
const handleScroll = (e) => {
  console.log(e);
};

const list = () => {
  const res = [];
  ['a', 'b', 'c', 'd', 'e'].forEach((key) => {
    res.push(...new Array(10).fill(0).map((num, index) => key + index));
  });
  console.log(res);
  return res;
};

const App = () => (
  <Select
    defaultValue="lucy"
    style={{
      width: 280,
    }}
    onChange={handleChange}
    open
    virtual={false}
    onPopupScroll={handleScroll}
    dropdownRender={(menu) => (
      <div style={{ display: 'grid', gridTemplateColumns: '100px auto' }}>
        <Anchor getContainer={() => document.querySelector('.rc-virtual-list-holder ')} >
          <Link href="#a1" title="a1" />
          <Link href="#b1" title="b1" />
          <Link href="#c1" title="c1" />
          <Link href="#d1" title="d1" />
          <Link href="#e1" title="e1" />
        </Anchor>
        <div id="menu">{menu}</div>
      </div>
    )}
  >
    {list().map((item) => (
      <Option id={item} value={item}>
        {item}
      </Option>
    ))}
  </Select>
);

export default App;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值