Skip to content

Commit

Permalink
fix(select-input): fix select-input popup content width calculation p…
Browse files Browse the repository at this point in the history
…roblem
  • Loading branch information
HaixingOoO committed Dec 5, 2023
1 parent b62f073 commit b845d2d
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/select-input/useOverlayInnerStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,24 @@ export default function useOverlayInnerStyle(

const matchWidthFunc = (triggerElement: HTMLElement, popupElement: HTMLElement) => {
if (!triggerElement || !popupElement) return;
// 避免因滚动条出现文本省略,预留宽度 8
const SCROLLBAR_WIDTH = popupElement.scrollHeight > popupElement.offsetHeight ? 8 : 0;

// popupElement的scrollBar宽度
const overlayScrollWidth = popupElement.offsetWidth - popupElement.scrollWidth;

/**
* issue:https://github.com/Tencent/tdesign-react/issues/2642
*
* popupElement的内容宽度不超过triggerElement的宽度,就使用triggerElement的宽度减去popup的滚动条宽度,
* 让popupElement的宽度加上scrollBar的宽度等于triggerElement的宽度;
*
* popupElement的内容宽度超过triggerElement的宽度,就使用popupElement的scrollWidth,
* 不用offsetWidth是会包含scrollBar的宽度
*/
const width =
popupElement.offsetWidth + SCROLLBAR_WIDTH >= triggerElement.offsetWidth
? popupElement.offsetWidth
: triggerElement.offsetWidth;
popupElement.offsetWidth - overlayScrollWidth > triggerElement.offsetWidth
? popupElement.scrollWidth
: triggerElement.offsetWidth - overlayScrollWidth;

let otherOverlayInnerStyle: React.CSSProperties = {};
if (popupProps && typeof popupProps.overlayInnerStyle === 'object' && !popupProps.overlayInnerStyle.width) {
otherOverlayInnerStyle = popupProps.overlayInnerStyle;
Expand Down

0 comments on commit b845d2d

Please sign in to comment.