1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/open-hand-choerodon-ui

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
util.tsx 1.4 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
heqiwei Отправлено 2 лет назад 92ad286
import measureTextWidth from '../_util/measureTextWidth';
function getContentWidth(element: HTMLElement, computedStyle: CSSStyleDeclaration): number {
const { width, boxSizing } = computedStyle;
if (boxSizing === 'content-box' && width && width !== 'auto') {
return parseFloat(width);
}
const contentWidth = width && width !== 'auto' ? parseFloat(width) : element.offsetWidth;
const { paddingLeft, paddingRight, borderLeftWidth, borderRightWidth } = computedStyle;
const pl = paddingLeft ? parseFloat(paddingLeft) : 0;
const pr = paddingRight ? parseFloat(paddingRight) : 0;
const bl = borderLeftWidth ? parseFloat(borderLeftWidth) : 0;
const br = borderRightWidth ? parseFloat(borderRightWidth) : 0;
return contentWidth - pl - pr - bl - br;
}
export default function isOverflow(element: HTMLElement | HTMLInputElement) {
const { textContent, ownerDocument } = element;
const { value } = element as HTMLInputElement;
if ((value || textContent) && ownerDocument) {
const { clientWidth, scrollWidth } = element;
if (scrollWidth > clientWidth) {
return true;
}
const { defaultView } = ownerDocument;
if (defaultView) {
const computedStyle = defaultView.getComputedStyle(element);
const contentWidth = Math.round(getContentWidth(element, computedStyle));
const textWidth = Math.round(measureTextWidth(textContent || value, computedStyle));
return (textWidth > contentWidth);
}
}
return false;
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://gitlife.ru/oschina-mirror/open-hand-choerodon-ui.git
git@gitlife.ru:oschina-mirror/open-hand-choerodon-ui.git
oschina-mirror
open-hand-choerodon-ui
open-hand-choerodon-ui
master