Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues #311 and #313 #315

Merged
merged 3 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist-archive/virtual-select-1.0.41.min.js

Large diffs are not rendered by default.

43 changes: 39 additions & 4 deletions dist/virtual-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var Utils = /*#__PURE__*/function () {
/**
* @param {any} text
* @returns {string}
* @memberof Utils
*/
function getString(text) {
return text || text === 0 ? text.toString() : '';
Expand All @@ -42,6 +43,7 @@ var Utils = /*#__PURE__*/function () {
* @param {any} value
* @param {boolean} defaultValue
* @returns {boolean}
* @memberof Utils
*/
}, {
key: "convertToBoolean",
Expand All @@ -61,6 +63,7 @@ var Utils = /*#__PURE__*/function () {
/**
* @param {any} value
* @returns {boolean}
* @memberof Utils
*/
}, {
key: "isEmpty",
Expand All @@ -81,6 +84,7 @@ var Utils = /*#__PURE__*/function () {
/**
* @param {any} value
* @returns {boolean}
* @memberof Utils
*/
}, {
key: "isNotEmpty",
Expand All @@ -93,6 +97,7 @@ var Utils = /*#__PURE__*/function () {
* @param {any} value
* @param {boolean} cloneArray
* @returns {any[]}
* @memberof Utils
*/
}, {
key: "removeItemFromArray",
Expand All @@ -112,6 +117,7 @@ var Utils = /*#__PURE__*/function () {
/**
* @param {any[]} array
* @returns {any[]}
* @memberof Utils
*/
}, {
key: "removeArrayEmpty",
Expand All @@ -128,6 +134,7 @@ var Utils = /*#__PURE__*/function () {
* @param {number} max
* @param {number} max
* @returns {number}
* @memberof Utils
*/
}, {
key: "getRandomInt",
Expand All @@ -141,6 +148,7 @@ var Utils = /*#__PURE__*/function () {
/**
* @param {string} text
* @return {string}
* @memberof Utils
*/
}, {
key: "regexEscape",
Expand All @@ -152,6 +160,7 @@ var Utils = /*#__PURE__*/function () {
/**
* @param {string} text
* @return {string}
* @memberof Utils
*/
}, {
key: "normalizeString",
Expand Down Expand Up @@ -182,6 +191,30 @@ var Utils = /*#__PURE__*/function () {
document.body.removeChild(tempElement);
return textWidth > container.clientWidth;
}

/**
* @static
* @param {string} text
* @return {string}
* @memberof Utils
*/
}, {
key: "replaceDoubleQuotesWithHTML",
value: function replaceDoubleQuotesWithHTML(text) {
return text.replace(/"/g, '"');
}

/**
* @static
* @param {string} text
* @return {boolean}
* @memberof Utils
*/
}, {
key: "containsHTML",
value: function containsHTML(text) {
return /<[a-z][\s\S]*>/i.test(text);
}
}]);
return Utils;
}();
Expand Down Expand Up @@ -1970,8 +2003,9 @@ var VirtualSelect = /*#__PURE__*/function () {
valueText.push(label);
selectedValuesCount += 1;
if (showValueAsTags) {
var valueTooltipForTags = _this10.getTooltipAttrText(label, !Utils.willTextOverflow($valueText.parentElement, label), true);
var valueTagHtml = "<span class=\"vscomp-value-tag\" data-index=\"".concat(d.index, "\" ").concat(valueTooltipForTags, ">\n <span class=\"vscomp-value-tag-content\">").concat(label, "</span>\n <span class=\"vscomp-value-tag-clear-button\">\n <i class=\"vscomp-clear-icon\"></i>\n </span>\n </span>");
//Will cause text overflow in runtime and if so, the tooltip information is prepared
var valueTooltipForTags = Utils.willTextOverflow($valueText.parentElement, label) ? _this10.getTooltipAttrText(label, false, true) : '';
var valueTagHtml = "<span class=\"vscomp-value-tag\" data-index=\"".concat(d.index, "\" ").concat(valueTooltipForTags, ">\n <span class=\"vscomp-value-tag-content\">").concat(label, "</span>\n <span class=\"vscomp-value-tag-clear-button\">\n <i class=\"vscomp-clear-icon\"></i>\n </span>\n </span>");
valueTooltip.push(valueTagHtml);
} else {
valueTooltip.push(label);
Expand Down Expand Up @@ -2369,8 +2403,9 @@ var VirtualSelect = /*#__PURE__*/function () {
value: function getTooltipAttrText(text) {
var ellipsisOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var allowHtml = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var tootltipText = Utils.containsHTML(text) ? Utils.replaceDoubleQuotesWithHTML(text) : text;
var data = {
'data-tooltip': text || '',
'data-tooltip': tootltipText || '',
'data-tooltip-enter-delay': this.tooltipEnterDelay,
'data-tooltip-z-index': this.zIndex,
'data-tooltip-font-size': this.tooltipFontSize,
Expand Down Expand Up @@ -2733,7 +2768,7 @@ var VirtualSelect = /*#__PURE__*/function () {
var $ele = this.$searchInput;
var hasNoOptions = !this.options.length && !this.hasServerSearch;
if ($ele) {
if (hasNoOptions) {
if (hasNoOptions && !this.allowNewOption) {
DomUtils.setAttr($ele, 'disabled', '');
this.$noOptions.focus();
} else {
Expand Down
2 changes: 1 addition & 1 deletion dist/virtual-select.min.js

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions docs/assets/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,34 @@ function initPageExamples() {
showValueAsTags: true,
});

initVirtualSelect({
ele: '#show-value-as-tags-select-with-html',
multiple: true,
search: true,
showValueAsTags: true,
options: [
{
label: '<i class="icon-fire" aria-hidden="true"></i> Option 1',
value: 1
},
{ label: '<i class="icon-plane" aria-hidden="true"></i> Option 2',
value: 2 },
{
label:
'<i class="icon-apple" aria-hidden="true"></i> This is a very long text to be selected in the selection!! This is a very long text to be selected in the selection!!',
value: 3
},
{
label:
'This is a very long text to be selected in the selection!! This is a very long text to be selected in the selection!!',
value: 4
}

],
selectedValue: [1,2]
});


initVirtualSelect({
ele: '#direction-rtl-select',
multiple: true,
Expand Down
3 changes: 2 additions & 1 deletion docs/assets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ section.cover {
margin-left: 12px;
}

#show-value-as-tags-select {
#show-value-as-tags-select,
#show-value-as-tags-select-with-html {
max-width: 400px;
}

Expand Down
43 changes: 39 additions & 4 deletions docs/assets/virtual-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var Utils = /*#__PURE__*/function () {
/**
* @param {any} text
* @returns {string}
* @memberof Utils
*/
function getString(text) {
return text || text === 0 ? text.toString() : '';
Expand All @@ -42,6 +43,7 @@ var Utils = /*#__PURE__*/function () {
* @param {any} value
* @param {boolean} defaultValue
* @returns {boolean}
* @memberof Utils
*/
}, {
key: "convertToBoolean",
Expand All @@ -61,6 +63,7 @@ var Utils = /*#__PURE__*/function () {
/**
* @param {any} value
* @returns {boolean}
* @memberof Utils
*/
}, {
key: "isEmpty",
Expand All @@ -81,6 +84,7 @@ var Utils = /*#__PURE__*/function () {
/**
* @param {any} value
* @returns {boolean}
* @memberof Utils
*/
}, {
key: "isNotEmpty",
Expand All @@ -93,6 +97,7 @@ var Utils = /*#__PURE__*/function () {
* @param {any} value
* @param {boolean} cloneArray
* @returns {any[]}
* @memberof Utils
*/
}, {
key: "removeItemFromArray",
Expand All @@ -112,6 +117,7 @@ var Utils = /*#__PURE__*/function () {
/**
* @param {any[]} array
* @returns {any[]}
* @memberof Utils
*/
}, {
key: "removeArrayEmpty",
Expand All @@ -128,6 +134,7 @@ var Utils = /*#__PURE__*/function () {
* @param {number} max
* @param {number} max
* @returns {number}
* @memberof Utils
*/
}, {
key: "getRandomInt",
Expand All @@ -141,6 +148,7 @@ var Utils = /*#__PURE__*/function () {
/**
* @param {string} text
* @return {string}
* @memberof Utils
*/
}, {
key: "regexEscape",
Expand All @@ -152,6 +160,7 @@ var Utils = /*#__PURE__*/function () {
/**
* @param {string} text
* @return {string}
* @memberof Utils
*/
}, {
key: "normalizeString",
Expand Down Expand Up @@ -182,6 +191,30 @@ var Utils = /*#__PURE__*/function () {
document.body.removeChild(tempElement);
return textWidth > container.clientWidth;
}

/**
* @static
* @param {string} text
* @return {string}
* @memberof Utils
*/
}, {
key: "replaceDoubleQuotesWithHTML",
value: function replaceDoubleQuotesWithHTML(text) {
return text.replace(/"/g, '&quot;');
}

/**
* @static
* @param {string} text
* @return {boolean}
* @memberof Utils
*/
}, {
key: "containsHTML",
value: function containsHTML(text) {
return /<[a-z][\s\S]*>/i.test(text);
}
}]);
return Utils;
}();
Expand Down Expand Up @@ -1970,8 +2003,9 @@ var VirtualSelect = /*#__PURE__*/function () {
valueText.push(label);
selectedValuesCount += 1;
if (showValueAsTags) {
var valueTooltipForTags = _this10.getTooltipAttrText(label, !Utils.willTextOverflow($valueText.parentElement, label), true);
var valueTagHtml = "<span class=\"vscomp-value-tag\" data-index=\"".concat(d.index, "\" ").concat(valueTooltipForTags, ">\n <span class=\"vscomp-value-tag-content\">").concat(label, "</span>\n <span class=\"vscomp-value-tag-clear-button\">\n <i class=\"vscomp-clear-icon\"></i>\n </span>\n </span>");
//Will cause text overflow in runtime and if so, the tooltip information is prepared
var valueTooltipForTags = Utils.willTextOverflow($valueText.parentElement, label) ? _this10.getTooltipAttrText(label, false, true) : '';
var valueTagHtml = "<span class=\"vscomp-value-tag\" data-index=\"".concat(d.index, "\" ").concat(valueTooltipForTags, ">\n <span class=\"vscomp-value-tag-content\">").concat(label, "</span>\n <span class=\"vscomp-value-tag-clear-button\">\n <i class=\"vscomp-clear-icon\"></i>\n </span>\n </span>");
valueTooltip.push(valueTagHtml);
} else {
valueTooltip.push(label);
Expand Down Expand Up @@ -2369,8 +2403,9 @@ var VirtualSelect = /*#__PURE__*/function () {
value: function getTooltipAttrText(text) {
var ellipsisOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var allowHtml = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var tootltipText = Utils.containsHTML(text) ? Utils.replaceDoubleQuotesWithHTML(text) : text;
var data = {
'data-tooltip': text || '',
'data-tooltip': tootltipText || '',
'data-tooltip-enter-delay': this.tooltipEnterDelay,
'data-tooltip-z-index': this.zIndex,
'data-tooltip-font-size': this.tooltipFontSize,
Expand Down Expand Up @@ -2733,7 +2768,7 @@ var VirtualSelect = /*#__PURE__*/function () {
var $ele = this.$searchInput;
var hasNoOptions = !this.options.length && !this.hasServerSearch;
if ($ele) {
if (hasNoOptions) {
if (hasNoOptions && !this.allowNewOption) {
DomUtils.setAttr($ele, 'disabled', '');
this.$noOptions.focus();
} else {
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/virtual-select.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ Show each selected values as tags with remove icon

<div id="show-value-as-tags-select"></div>

Show each selected values as tags with some containing HTML

<div id="show-value-as-tags-select-with-html"></div>

```js
VirtualSelect.init({
...
Expand Down
3 changes: 2 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet" />

<link href="https://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
<link rel="stylesheet" href="assets/external/vue.css" />
<link rel="stylesheet" href="assets/external/flags.css" />
<link rel="stylesheet" href="assets/virtual-select.min.css" />
Expand Down Expand Up @@ -49,7 +50,7 @@
<body>
<div id="app"></div>

<script src="assets/virtual-select.min.js"></script>
<script src="assets/virtual-select.js"></script>
<script src="assets/tooltip.min.js"></script>
<script src="assets/script.js"></script>

Expand Down
Loading