当前位置: 首页 > news >正文

element plus el-table show-overflow-tooltip实现源码

element plus 2.7.2 版本

文件地址:packages/components/table/src/table-body/events-helper.ts

核心代码

const getPadding = (el: HTMLElement) => {const style = window.getComputedStyle(el, null)const paddingLeft = Number.parseInt(style.paddingLeft, 10) || 0const paddingRight = Number.parseInt(style.paddingRight, 10) || 0const paddingTop = Number.parseInt(style.paddingTop, 10) || 0const paddingBottom = Number.parseInt(style.paddingBottom, 10) || 0return {left: paddingLeft,right: paddingRight,top: paddingTop,bottom: paddingBottom,}}const handleCellMouseEnter = (event: MouseEvent,row: T,tooltipOptions: TableOverflowTooltipOptions) => {const table = parentconst cell = getCell(event)const namespace = table?.vnode.el?.dataset.prefixif (cell) {const column = getColumnByCell({columns: props.store.states.columns.value,},cell,namespace)if (cell.rowSpan > 1) {toggleRowClassByCell(cell.rowSpan, event, addClass)}const hoverState = (table.hoverState = { cell, column, row })table?.emit('cell-mouse-enter',hoverState.row,hoverState.column,hoverState.cell,event)}if (!tooltipOptions) {return}// 判断是否text-overflow, 如果是就显示tooltipconst cellChild = (event.target as HTMLElement).querySelector('.cell') as HTMLElementif (!(hasClass(cellChild, `${namespace}-tooltip`) &&cellChild.childNodes.length)) {return}/****从这里开始都是***/// use range width instead of scrollWidth to determine whether the text is overflowing// to address a potential FireFox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1074543#c3const range = document.createRange()range.setStart(cellChild, 0)range.setEnd(cellChild, cellChild.childNodes.length)/** detail: https://github.com/element-plus/element-plus/issues/10790*  What went wrong?*  UI > Browser > Zoom, In Blink/WebKit, getBoundingClientRect() sometimes returns inexact values, probably due to lost precision during internal calculations. In the example above:*    - Expected: 188*    - Actual: 188.00000762939453*/let rangeWidth = range.getBoundingClientRect().widthlet rangeHeight = range.getBoundingClientRect().heightconst offsetWidth = rangeWidth - Math.floor(rangeWidth)const { width: cellChildWidth, height: cellChildHeight } =cellChild.getBoundingClientRect()if (offsetWidth < 0.001) {rangeWidth = Math.floor(rangeWidth)}const offsetHeight = rangeHeight - Math.floor(rangeHeight)if (offsetHeight < 0.001) {rangeHeight = Math.floor(rangeHeight)}const { top, left, right, bottom } = getPadding(cellChild)const horizontalPadding = left + rightconst verticalPadding = top + bottomif (rangeWidth + horizontalPadding > cellChildWidth ||rangeHeight + verticalPadding > cellChildHeight ||cellChild.scrollWidth > cellChildWidth) {createTablePopper(tooltipOptions,cell.innerText || cell.textContent,cell,table)}}

http://www.mrgr.cn/news/15520.html

相关文章:

  • Python编程实战营:四款实用小项目助你快速入门,从零开始打造你的个人项目集!
  • Mybatis多表关联查询注解方式动态SQL详细笔记
  • 【小白深度学习入门】【2】池化层详解:工作原理、维度计算、池化类型
  • elasticsearch整合java使用创建索引、指定索引映射、操作添加文档、删除文档、更新文档、批量操作
  • HTML静态网页成品作业(HTML+CSS)——非遗徽州木雕网页(6个页面)
  • PHP房屋出售出租多端多平台预约系统小程序源码
  • 深度学习环境安装与验证指南
  • 安全运维--Linux常用命令
  • 黑悟空!一区预定!原创首发!SLWCHOA-Transformer-LSTM混合改进策略的黑猩猩优化算法多变量时间序列预测
  • HS编码的作用是什么
  • 【最新】高效可用的Docker仓库源
  • 概率论与高等数学、线性代数的联系及应用
  • HarmonyOs如何获取rawfile目录下的所有文件列表
  • 控制理论:MindOpt Python API求解模型预测控制问题(Model Predictive Control)
  • 使用maven快速生成打包文件2
  • 【Rust光年纪】保护用户数据安全隐私:探秘Rust机密计算与安全库
  • 科技赋能 重塑未来医疗丨共谋医疗信息化新方向,2024东北医院信息网络大会圆满落幕!
  • Oracle中数据类型 NVARCHAR2 与 VARCHAR2 的对比
  • 最好的超声波清洗机是哪一款?好用的超声波清洗机排名
  • 嘴上说“摆烂”的90后,考了最多的PMP证书......