From 77c8cafa4eea47c26d2706d9850f527d3bc02c6c Mon Sep 17 00:00:00 2001 From: Xavier Carron <33637571+xav-car@users.noreply.github.com> Date: Wed, 17 Apr 2024 15:56:32 +0200 Subject: [PATCH] remove usage of did insert / update --- addon/common/add-dynamic-style-tag.js | 8 --- .../pix-filterable-and-searchable-select.hbs | 1 - .../pix-filterable-and-searchable-select.js | 48 ++++++++------- addon/components/pix-pagination.hbs | 2 +- addon/components/pix-pagination.js | 18 +++--- addon/components/pix-select.hbs | 2 - addon/components/pix-select.js | 58 ++++++++----------- app/services/element-helper.js | 32 ++++++++++ ...x-filterable-and-searchable-select-test.js | 10 ++-- .../integration/components/pix-select-test.js | 6 +- 10 files changed, 99 insertions(+), 86 deletions(-) delete mode 100644 addon/common/add-dynamic-style-tag.js create mode 100644 app/services/element-helper.js diff --git a/addon/common/add-dynamic-style-tag.js b/addon/common/add-dynamic-style-tag.js deleted file mode 100644 index 700dc42f6..000000000 --- a/addon/common/add-dynamic-style-tag.js +++ /dev/null @@ -1,8 +0,0 @@ -export function createClass(name, rules) { - var style = document.createElement('style'); - style.type = 'text/css'; - document.getElementsByTagName('head')[0].appendChild(style); - - if (!(style.sheet || {}).insertRule) (style.styleSheet || style.sheet).addRule(name, rules); - else style.sheet.insertRule(name + '{' + rules + '}', 0); -} diff --git a/addon/components/pix-filterable-and-searchable-select.hbs b/addon/components/pix-filterable-and-searchable-select.hbs index b1d33cebb..c96021b42 100644 --- a/addon/components/pix-filterable-and-searchable-select.hbs +++ b/addon/components/pix-filterable-and-searchable-select.hbs @@ -28,7 +28,6 @@ <:default as |option|>{{option.label}} { + const baseFontRemRatio = Number( + getComputedStyle(document.querySelector('html')).fontSize.match(/\d+(\.\d+)?/)[0], + ); + + const multiSelectWidth = document + .getElementById(this.pixMultiSelectId) + .getBoundingClientRect().width; + + const selectWidth = Math.ceil(multiSelectWidth / baseFontRemRatio); + + const className = `sizing-select-${this.pixSelectId}`; + this.elementHelper.createClass(`.${className}`, `width: calc(100% - ${selectWidth}rem);`); + + element.className = element.className + ' ' + className; + }); + } @action selectCategories(categories) { @@ -47,22 +69,4 @@ export default class PixFilterableAndSearchableSelect extends Component { return selectableOptions; } - - @action - setSelectWidth(element) { - const baseFontRemRatio = Number( - getComputedStyle(document.querySelector('html')).fontSize.match(/\d+(\.\d+)?/)[0], - ); - - const multiSelectWidth = document - .getElementById(this.pixMultiSelectId) - .getBoundingClientRect().width; - - const selectWidth = Math.ceil(multiSelectWidth / baseFontRemRatio); - - const className = `sizing-select-${this.pixSelectId}`; - createClass(`.${className}`, `width: calc(100% - ${selectWidth}rem);`); - - element.className = element.className + ' ' + className; - } } diff --git a/addon/components/pix-pagination.hbs b/addon/components/pix-pagination.hbs index 13283b711..7813f1788 100644 --- a/addon/components/pix-pagination.hbs +++ b/addon/components/pix-pagination.hbs @@ -1,4 +1,4 @@ -