From 5dacb450f63595c5f88bc2cbced708f1bc485fde Mon Sep 17 00:00:00 2001 From: alokhyland Date: Wed, 12 Jun 2024 14:14:23 +0530 Subject: [PATCH] ELEMENTS-1672: Apply text-overflow and tooltip to multiple selected items in nuxeo-selectivity --- ui/widgets/nuxeo-selectivity.js | 61 ++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/ui/widgets/nuxeo-selectivity.js b/ui/widgets/nuxeo-selectivity.js index 02c10b81fa..fa13c950f0 100644 --- a/ui/widgets/nuxeo-selectivity.js +++ b/ui/widgets/nuxeo-selectivity.js @@ -25,6 +25,8 @@ import { html } from '@polymer/polymer/lib/utils/html-tag.js'; import { mixinBehaviors } from '@polymer/polymer/lib/legacy/class.js'; import {I18nBehavior} from "../nuxeo-i18n-behavior"; import '@polymer/iron-icon/iron-icon.js'; +import { IronResizableBehavior } from '@polymer/iron-resizable-behavior/iron-resizable-behavior.js'; +import './nuxeo-tooltip.js'; /** * @license @@ -3429,8 +3431,32 @@ typedArrayTags[weakMapTag] = false; item, ), )); - + this.input.parentNode.insertBefore(el, this.input); + const textElement = el.querySelector('.selectivity-multiple-selected-item.selectivity-text-container') + const elementWidth = this._calculateElementWidth(textElement); + const containerElement = this._getHTMLRootNode(textElement) + const containerElementWidth = this._calculateElementWidth(containerElement) + if(elementWidth>0 && elementWidth>containerElementWidth) { + textElement.setAttribute('style', `max-width:${containerElementWidth}px`); + } + }, + + _getHTMLRootNode(element){ + let currentElement = element; + const parentElement = currentElement.closest(".selectivity-multiple-input-container") + return parentElement; + }, + + + + _calculateElementWidth(element){ + const currrentElement = getComputedStyle(element); + const paddingX = parseFloat(currrentElement.paddingLeft) + parseFloat(currrentElement.paddingRight); + const borderX = parseFloat(currrentElement.borderLeftWidth) + parseFloat(currrentElement.borderRightWidth); + const scrollBarWidth = element.offsetWidth - element.clientWidth; + const elementWidth = (element .offsetWidth - paddingX - borderX - scrollBarWidth -2) ; + return elementWidth }, /** @@ -6583,7 +6609,7 @@ typedArrayTags[weakMapTag] = false; * @demo demo/nuxeo-selectivity/index.html */ class SelectivityElement - extends mixinBehaviors([I18nBehavior, IronFormElementBehavior, IronValidatableBehavior], Nuxeo.Element) { + extends mixinBehaviors([I18nBehavior, IronFormElementBehavior, IronValidatableBehavior, IronResizableBehavior], Nuxeo.Element) { static get is() { return 'nuxeo-selectivity'; @@ -7108,6 +7134,14 @@ typedArrayTags[weakMapTag] = false; height: 2px; background-color: var(--nuxeo-primary-color, #0066ff); } + .selectivity-text-container { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + .multipleSelectedItemText { + display:inline-block; + } @@ -7171,10 +7205,17 @@ typedArrayTags[weakMapTag] = false; multipleSelectedItem: (opts) => { const extraClass = opts.highlighted ? ' highlighted' : ''; - return ` + ${this.selectionFormatter(opts.item || opts)} + `:'' + return (`${opts.removable ? `` - : ``}${this.selectionFormatter(opts.item || opts)}` + : ``}${this.selectionFormatter(opts.item || opts)} + ${toolTipElement} + + `) }, }, }; @@ -7188,6 +7229,9 @@ typedArrayTags[weakMapTag] = false; options.placeholder = this.placeholder; options.allowClear = !this.required && !this.multiple; // allowClear only works on single-value mode } + else{ + this.addEventListener('iron-resize', this._resize); + } if (this.data) { options.items = this._wrap(this.data); @@ -7274,9 +7318,18 @@ typedArrayTags[weakMapTag] = false; this._selectivity = null; this._visibilityObserver.unobserve(this); this._scrollParent.removeEventListener('scroll', this._updateDropdownPosition.bind(this)); + this.removeEventListener('iron-resize', this._resize); super.disconnectedCallback(); } + + + _resize() { + this._selectivity && this._selectivity.options.readOnly && + this._selectivity._reset() && + this._selectivity.rerenderSelection(); + } + _updateDropdownPosition() { if (this._selectivity) { this._selectivity.positionDropdown();