From 5c0879750055330f1a4dc45ab26954acedb12d9f Mon Sep 17 00:00:00 2001 From: mertsincan Date: Fri, 2 Oct 2020 13:23:19 +0300 Subject: [PATCH 1/7] Fixed #523 - Tooltip doesn't close in scrollable containers --- src/components/tooltip/Tooltip.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/components/tooltip/Tooltip.js b/src/components/tooltip/Tooltip.js index a861183af..36d609a64 100755 --- a/src/components/tooltip/Tooltip.js +++ b/src/components/tooltip/Tooltip.js @@ -1,5 +1,6 @@ import UniqueComponentId from '../utils/UniqueComponentId'; import DomHandler from '../utils/DomHandler'; +import ConnectedOverlayScrollHandler from '../utils/ConnectedOverlayScrollHandler'; function bindEvents(el) { const modifiers = el.$_ptooltipModifiers; @@ -27,6 +28,22 @@ function unbindEvents(el) { } } +function bindScrollListener(el) { + if (!el.$_ptooltipScrollHandler) { + el.$_ptooltipScrollHandler = new ConnectedOverlayScrollHandler(el, function() { + hide(el); + }); + } + + el.$_ptooltipScrollHandler.bindScrollListener(); +} + +function unbindScrollListener(el) { + if (el.$_ptooltipScrollHandler) { + el.$_ptooltipScrollHandler.unbindScrollListener(); + } +} + function onMouseEnter(event) { show(event.currentTarget); } @@ -61,10 +78,13 @@ function show(el) { hide(el); this.removeEventListener('resize', onWindowResize); }); + + bindScrollListener(el); } function hide(el) { remove(el); + unbindScrollListener(el); } function getTooltipElement(el) { @@ -225,6 +245,11 @@ const Tooltip = { unmounted(el) { remove(el); unbindEvents(el); + + if (el.$_ptooltipScrollHandler) { + el.$_ptooltipScrollHandler.destroy(); + el.$_ptooltipScrollHandler = null; + } }, updated(el, options) { el.$_ptooltipModifiers = options.modifiers; @@ -232,4 +257,4 @@ const Tooltip = { } }; -export default Tooltip; \ No newline at end of file +export default Tooltip; From f010b971de942254a808883283d106b2ddcd9b6c Mon Sep 17 00:00:00 2001 From: mertsincan Date: Fri, 9 Oct 2020 11:05:23 +0300 Subject: [PATCH 2/7] Fixed #533 - InputNumber cannot set value when format property is false --- src/components/inputnumber/InputNumber.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/inputnumber/InputNumber.vue b/src/components/inputnumber/InputNumber.vue index d00fd8e83..6055af875 100755 --- a/src/components/inputnumber/InputNumber.vue +++ b/src/components/inputnumber/InputNumber.vue @@ -228,7 +228,7 @@ export default { return formattedValue; } - return value; + return value.toString(); } return ''; From 5ce105335c9e68da8a889cacc651e53188e4c858 Mon Sep 17 00:00:00 2001 From: mertsincan Date: Fri, 9 Oct 2020 11:06:51 +0300 Subject: [PATCH 3/7] Fixed #532 - InputNumber with spinner mode throws a JS exception --- src/components/inputnumber/InputNumber.vue | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/inputnumber/InputNumber.vue b/src/components/inputnumber/InputNumber.vue index 6055af875..85c8d88d8 100755 --- a/src/components/inputnumber/InputNumber.vue +++ b/src/components/inputnumber/InputNumber.vue @@ -659,6 +659,8 @@ export default { return value; }, updateInput(value, insertedValueStr, operation) { + insertedValueStr = insertedValueStr || ''; + let inputValue = this.$refs.input.$el.value; let newValue = this.formatValue(value); let currentLength = inputValue.length; From 946e3b2e8d9a8367e1cf6ba61bd5d98b220e5cba Mon Sep 17 00:00:00 2001 From: mertsincan Date: Fri, 9 Oct 2020 11:34:20 +0300 Subject: [PATCH 4/7] Fixed #530 - Problems when typing or pasting numbers into InputNumber --- src/components/inputnumber/InputNumber.vue | 62 ++++++++++++++++------ 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/src/components/inputnumber/InputNumber.vue b/src/components/inputnumber/InputNumber.vue index 85c8d88d8..8ca32d0a3 100755 --- a/src/components/inputnumber/InputNumber.vue +++ b/src/components/inputnumber/InputNumber.vue @@ -116,6 +116,8 @@ export default { _index: null, groupChar: '', isSpecialChar: null, + prefixChar: null, + suffixChar: null, timer: null, data() { return { @@ -178,8 +180,8 @@ export default { this._group = this.getGroupingExpression(); this._minusSign = this.getMinusSignExpression(); this._currency = this.getCurrencyExpression(); - this._suffix = new RegExp(`[${this.suffix||''}]`, 'g'); - this._prefix = new RegExp(`[${this.prefix||''}]`, 'g'); + this._suffix = this.getSuffixExpression(); + this._prefix = this.getPrefixExpression(); this._index = d => index.get(d); }, updateConstructParser(newValue, oldValue) { @@ -208,6 +210,29 @@ export default { return new RegExp(`[]`,'g'); }, + getPrefixExpression() { + if (this.prefix) { + this.prefixChar = this.prefix; + } + else { + const formatter = new Intl.NumberFormat(this.props.locale, {style: this.mode, currency: this.currency, currencyDisplay: this.currencyDisplay}); + this.prefixChar = formatter.format(1).split('1')[0]; + } + + return new RegExp(`${this.prefixChar||''}`, 'g'); + }, + getSuffixExpression() { + if (this.props.suffix) { + this.suffixChar = this.suffix; + } + else { + const formatter = new Intl.NumberFormat(this.props.locale, {style: this.mode, currency: this.currency, currencyDisplay: this.currencyDisplay, + minimumFractionDigits: 0, maximumFractionDigits: 0}); + this.suffixChar = formatter.format(1).split('1')[1]; + } + + return new RegExp(`${this.suffixChar||''}`, 'g'); + }, formatValue(value) { if (value != null) { if (value === '-') { // Minus sign @@ -511,33 +536,40 @@ export default { } else { const maxFractionDigits = this.numberFormat.resolvedOptions().maximumFractionDigits; + const operation = selectionStart !== selectionEnd ? 'range-insert' : 'insert'; if (decimalCharIndex > 0 && selectionStart > decimalCharIndex) { if ((selectionStart + text.length - (decimalCharIndex + 1)) <= maxFractionDigits) { newValueStr = inputValue.slice(0, selectionStart) + text + inputValue.slice(selectionStart + text.length); - this.updateValue(event, newValueStr, text, 'insert'); + this.updateValue(event, newValueStr, text, operation); } } else { newValueStr = this.insertText(inputValue, text, selectionStart, selectionEnd); - const operation = selectionStart !== selectionEnd ? 'range-insert' : 'insert'; this.updateValue(event, newValueStr, text, operation); } } }, insertText(value, text, start, end) { - let newValueStr; + let textSplit = text.split('.'); - if ((end - start) === value.length) - newValueStr = text; - else if (start === 0) - newValueStr = text + value.slice(end); - else if (end === value.length) - newValueStr = value.slice(0, start) + text; - else - newValueStr = value.slice(0, start) + text + value.slice(end); - - return newValueStr; + if (textSplit.length === 2) { + const decimalCharIndex = value.slice(start, end).search(this._decimal); + this._decimal.lastIndex = 0; + return (decimalCharIndex > 0) ? value.slice(0, start) + this.formatValue(text) + value.slice(end) : (value || this.formatValue(text)); + } + else if ((end - start) === value.length) { + return this.formatValue(text); + } + else if (start === 0) { + return text + value.slice(end); + } + else if (end === value.length) { + return value.slice(0, start) + text; + } + else { + return value.slice(0, start) + text + value.slice(end); + } }, deleteRange(value, start, end) { let newValueStr; From 2bb73009795f1eb242b74d2cc284387df6faf038 Mon Sep 17 00:00:00 2001 From: mertsincan Date: Fri, 9 Oct 2020 11:36:57 +0300 Subject: [PATCH 5/7] Fixed #531 - inputNumber with numeric prefix is not working as expected --- src/components/inputnumber/InputNumber.vue | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/inputnumber/InputNumber.vue b/src/components/inputnumber/InputNumber.vue index 8ca32d0a3..c1abc24ac 100755 --- a/src/components/inputnumber/InputNumber.vue +++ b/src/components/inputnumber/InputNumber.vue @@ -189,6 +189,9 @@ export default { this.constructParser(); } }, + escapeRegExp(text) { + return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); + }, getDecimalExpression() { const formatter = new Intl.NumberFormat(this.locale, {useGrouping: false}); return new RegExp(`[${formatter.format(1.1).trim().replace(this._numeral, '')}]`, 'g'); @@ -219,7 +222,7 @@ export default { this.prefixChar = formatter.format(1).split('1')[0]; } - return new RegExp(`${this.prefixChar||''}`, 'g'); + return new RegExp(`${this.escapeRegExp(this.prefixChar||'')}`, 'g'); }, getSuffixExpression() { if (this.props.suffix) { @@ -231,7 +234,7 @@ export default { this.suffixChar = formatter.format(1).split('1')[1]; } - return new RegExp(`${this.suffixChar||''}`, 'g'); + return new RegExp(`${this.escapeRegExp(this.suffixChar||'')}`, 'g'); }, formatValue(value) { if (value != null) { From 583aaa1b6deab1a9e6a0f0d3e270ddd4ab72429a Mon Sep 17 00:00:00 2001 From: mertsincan Date: Fri, 9 Oct 2020 11:54:28 +0300 Subject: [PATCH 6/7] Refactor on InputNumber --- src/components/inputnumber/InputNumber.vue | 32 +++++++++++++++------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/components/inputnumber/InputNumber.vue b/src/components/inputnumber/InputNumber.vue index c1abc24ac..b80ec036a 100755 --- a/src/components/inputnumber/InputNumber.vue +++ b/src/components/inputnumber/InputNumber.vue @@ -198,7 +198,7 @@ export default { }, getGroupingExpression() { const formatter = new Intl.NumberFormat(this.locale, {useGrouping: true}); - this.groupChar = formatter.format(1000000).trim().replace(this._numeral, ''); + this.groupChar = formatter.format(1000000).trim().replace(this._numeral, '').charAt(0); return new RegExp(`[${this.groupChar}]`, 'g'); }, getMinusSignExpression() { @@ -218,18 +218,18 @@ export default { this.prefixChar = this.prefix; } else { - const formatter = new Intl.NumberFormat(this.props.locale, {style: this.mode, currency: this.currency, currencyDisplay: this.currencyDisplay}); + const formatter = new Intl.NumberFormat(this.locale, {style: this.mode, currency: this.currency, currencyDisplay: this.currencyDisplay}); this.prefixChar = formatter.format(1).split('1')[0]; } return new RegExp(`${this.escapeRegExp(this.prefixChar||'')}`, 'g'); }, getSuffixExpression() { - if (this.props.suffix) { + if (this.suffix) { this.suffixChar = this.suffix; } else { - const formatter = new Intl.NumberFormat(this.props.locale, {style: this.mode, currency: this.currency, currencyDisplay: this.currencyDisplay, + const formatter = new Intl.NumberFormat(this.locale, {style: this.mode, currency: this.currency, currencyDisplay: this.currencyDisplay, minimumFractionDigits: 0, maximumFractionDigits: 0}); this.suffixChar = formatter.format(1).split('1')[1]; } @@ -262,12 +262,13 @@ export default { return ''; }, parseValue(text) { - let filteredText = text.trim() + let filteredText = text + .replace(this._suffix, '') + .replace(this._prefix, '') + .trim() .replace(/\s/g, '') .replace(this._currency, '') .replace(this._group, '') - .replace(this._suffix, '') - .replace(this._prefix, '') .replace(this._minusSign, '-') .replace(this._decimal, '.') .replace(this._numeral, this._index); @@ -492,6 +493,9 @@ export default { } } }, + allowMinusSign() { + return this.min === null || this.min < 0; + }, isMinusSign(char) { if (this._minusSign.test(char)) { this._minusSign.lastIndex = 0; @@ -509,8 +513,14 @@ export default { return false; }, insert(event, text, sign = { isDecimalSign: false, isMinusSign: false }) { - let selectionStart = this.$refs.input.$el.selectionStart; - let selectionEnd = this.$refs.input.$el.selectionEnd; + const minusCharIndexOnText = text.search(this._minusSign); + this._minusSign.lastIndex = 0; + if (!this.allowMinusSign() && minusCharIndexOnText !== -1) { + return; + } + + const selectionStart = this.$refs.input.$el.selectionStart; + const selectionEnd = this.$refs.input.$el.selectionEnd; let inputValue = this.$refs.input.$el.value.trim(); const decimalCharIndex = inputValue.search(this._decimal); this._decimal.lastIndex = 0; @@ -704,7 +714,9 @@ export default { this.$refs.input.$el.value = newValue; this.$refs.input.$el.setSelectionRange(0, 0); this.initCursor(); - this.$refs.input.$el.setSelectionRange(this.$refs.input.$el.selectionStart + 1, this.$refs.input.$el.selectionStart + 1); + const prefixLength = (this.prefixChar || '').length; + const selectionEnd = prefixLength + insertedValueStr.length; + this.$refs.input.$el.setSelectionRange(selectionEnd, selectionEnd); } else { let selectionStart = this.$refs.input.$el.selectionStart; From b83486be97b9cf2ec38b0b252ada70d9c886a52d Mon Sep 17 00:00:00 2001 From: mertsincan Date: Fri, 9 Oct 2020 12:04:44 +0300 Subject: [PATCH 7/7] Fixed #537 - The 'disabled' option has no effect on InputNumber --- src/components/inputnumber/InputNumber.vue | 40 +++++++++++++++------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/components/inputnumber/InputNumber.vue b/src/components/inputnumber/InputNumber.vue index b80ec036a..815c295ed 100755 --- a/src/components/inputnumber/InputNumber.vue +++ b/src/components/inputnumber/InputNumber.vue @@ -304,18 +304,26 @@ export default { this.handleOnInput(event, currentValue, newValue); }, onUpButtonMouseDown(event) { - this.$refs.input.$el.focus(); - this.repeat(event, null, 1); - event.preventDefault(); + if (!this.$attrs.disabled) { + this.$refs.input.$el.focus(); + this.repeat(event, null, 1); + event.preventDefault(); + } }, onUpButtonMouseUp() { - this.clearTimer(); + if (!this.$attrs.disabled) { + this.clearTimer(); + } }, onUpButtonMouseLeave() { - this.clearTimer(); + if (!this.$attrs.disabled) { + this.clearTimer(); + } }, onUpButtonKeyUp() { - this.clearTimer(); + if (!this.$attrs.disabled) { + this.clearTimer(); + } }, onUpButtonKeyDown(event) { if (event.keyCode === 32 || event.keyCode === 13) { @@ -323,18 +331,26 @@ export default { } }, onDownButtonMouseDown(event) { - this.$refs.input.$el.focus(); - this.repeat(event, null, -1); - event.preventDefault(); + if (!this.$attrs.disabled) { + this.$refs.input.$el.focus(); + this.repeat(event, null, -1); + event.preventDefault(); + } }, onDownButtonMouseUp() { - this.clearTimer(); + if (!this.$attrs.disabled) { + this.clearTimer(); + } }, onDownButtonMouseLeave() { - this.clearTimer(); + if (!this.$attrs.disabled) { + this.clearTimer(); + } }, onDownButtonKeyUp() { - this.clearTimer(); + if (!this.$attrs.disabled) { + this.clearTimer(); + } }, onDownButtonKeyDown(event) { if (event.keyCode === 32 || event.keyCode === 13) {