UNPKG

@progress/kendo-angular-dropdowns

Version:

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

61 lines (60 loc) 2.18 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'; /** * Stores the initially resolved scrollbar width value. */ let SCROLLBAR_WIDTH; /** * @hidden * * Gets the default scrollbar width for the current environment. * * Returns the scrollbar width in pixels. */ 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. * * Returns `true` if all columns have a valid width, otherwise returns `false`. */ 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 based on the columns' width configuration. * * Ignores hidden columns and columns that do not match the provided media query. * Returns `null` if any column does not have a valid width. */ 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); };