首页 > 其他 > 详细

优化Ant Design 下拉框伴页面滚动

时间:2021-03-08 13:59:00      阅读:46      评论:0      收藏:0      [点我收藏+]

在项目中使用antd的form组件,当一屏显示不完存在滚动条时,滑动滚动条会出现form中的下拉框伴随页面滚动的情况。通过重新绑定下拉框对应的父级定位元素,可优化这样的现象。

一、封装通用方法

export const scrollSelectFormUtils = (id: string) => {
  //获取当前元素
  const getPopupContainer: RenderDOMFunc = () => {
    return document.getElementById(id) as HTMLElement
  }
  //定位当前元素
  const scrollSelectFormProps: {
    id: string
    style: {
      // declare position css type
      position:
        | ‘inherit‘
        | ‘initial‘
        | ‘revert‘
        | ‘unset‘
        | ‘-webkit-sticky‘
        | ‘absolute‘
        | ‘fixed‘
        | ‘relative‘
        | ‘static‘
        | ‘sticky‘
        | undefined
    }
  } = {
    id,
    style: {
      position: ‘relative‘,
    },
  }
  return {
    getPopupContainer,
    scrollSelectFormProps,
  }
}

二、页面引入使用

import { scrollSelectFormUtils } from ‘****‘ //引入
//获取定义
const { getPopupContainer, scrollSelectFormProps } = scrollSelectFormUtils(
  ‘abnormal-list‘
)
//绑定form
<Form layout=‘inline‘ form={form} {...scrollSelectFormProps}>
 //绑定select
 <Select getPopupContainer={getPopupContainer}>

 </Select>

</Form>

 

showtooltip

优化Ant Design 下拉框伴页面滚动

原文:https://www.cnblogs.com/coding8832/p/14499001.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!