UNPKG

@progress/kendo-angular-dropdowns

Version:

A wide variety of native Angular dropdown components including AutoComplete, ComboBox, DropDownList, DropDownTree, MultiColumnComboBox, MultiSelect, and MultiSelectTree

56 lines (55 loc) 2.12 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { isPresent } from '../../common/util'; /** * Persists the intially resolved scrollbar width value. */ let SCROLLBAR_WIDTH; /** * @hidden * * Gets the default scrollbar width accoring to the current environment. */ export const scrollbarWidth = () => { // calculate scrollbar width only once, then return the memoized value if (isNaN(SCROLLBAR_WIDTH)) { const div = document.createElement('div'); div.style.cssText = 'overflow: scroll; overflow-x: hidden; zoom: 1; clear: both; display: block;'; div.innerHTML = ' '; document.body.appendChild(div); SCROLLBAR_WIDTH = div.offsetWidth - div.scrollWidth; document.body.removeChild(div); } return SCROLLBAR_WIDTH; }; /** * Checks if all columns have a valid user-defined width. */ const allColumnsWidthsSet = (columns) => { if (!isPresent(columns) || columns.length === 0) { return false; } return columns.toArray().every(column => !isNaN(column.width) && column.width > 0); }; /** * @hidden * * Calculates the row width according to the passed columns width configuration. * Hidden columns and such that don't match the provided media query are ignored. * If some of the columns don't have a preset width or have an invalid width value, the function returns `null`. */ export const getRowWidthFromColumnsMeta = (columns) => { if (!allColumnsWidthsSet(columns)) { return null; } const bordersWidth = 2; const initialRowWidht = scrollbarWidth() + bordersWidth; return columns.reduce((totalWidth, column) => { if (!column.hidden && column.matchesMedia) { totalWidth += parseInt(column.width, 10); } return totalWidth; }, initialRowWidht); };