Skip to content

Commit

Permalink
bug fix and feature update
Browse files Browse the repository at this point in the history
  • Loading branch information
sa-si-dev committed Jan 1, 2023
1 parent 18afcd6 commit 91ec18e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 26 deletions.
16 changes: 5 additions & 11 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ export class Utils {
if (value.length === 0) {
result = true;
}
} else if (typeof value === 'object') {
if (Object.keys(value).length === 0) {
result = true;
}
} else if (typeof value === 'object' && Object.keys(value).length === 0) {
result = true;
}

return result;
Expand Down Expand Up @@ -101,15 +99,11 @@ export class Utils {
return Math.floor(Math.random() * (maxN - minN - 1)) + minN;
}


/**
* @static
* @param {string} text
* @return {string}
* @memberof Utils
* @return {string}
*/
static regexEscape(text) {
return text.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
};

return text.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
}
}
27 changes: 12 additions & 15 deletions src/virtual-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const dataProps = [
'dropboxWrapper',
'emptyValue',
'enableSecureText',
'focusSelectedOptionOnOpen',
'hasOptionDescription',
'hideClearButton',
'hideValueTooltipOnSelectAll',
Expand Down Expand Up @@ -255,10 +256,9 @@ export class VirtualSelect {
const { labelRenderer, disableOptionGroupCheckbox, uniqueId, searchGroup } = this;
const hasLabelRenderer = typeof labelRenderer === 'function';
const { convertToBoolean } = Utils;
const { regexEscape } = Utils;

if (markSearchResults) {
searchRegex = new RegExp(`(${regexEscape(this.searchValue)})`, 'gi');
searchRegex = new RegExp(`(${Utils.regexEscape(this.searchValue)})`, 'gi');
}

if (this.multiple) {
Expand Down Expand Up @@ -758,6 +758,7 @@ export class VirtualSelect {
this.required = convertToBoolean(options.required);
this.autofocus = convertToBoolean(options.autofocus);
this.useGroupValue = convertToBoolean(options.useGroupValue);
this.focusSelectedOptionOnOpen = convertToBoolean(options.focusSelectedOptionOnOpen);
this.noOptionsText = options.noOptionsText;
this.noSearchResultsText = options.noSearchResultsText;
this.selectAllText = options.selectAllText;
Expand Down Expand Up @@ -864,6 +865,7 @@ export class VirtualSelect {
hideValueTooltipOnSelectAll: true,
emptyValue: '',
searchDelay: 300,
focusSelectedOptionOnOpen: true,
};

if (options.hasOptionDescription) {
Expand Down Expand Up @@ -1760,7 +1762,7 @@ export class VirtualSelect {
setScrollTop() {
const { selectedValues } = this;

if (this.showSelectedOptionsFirst || selectedValues.length === 0) {
if (this.showSelectedOptionsFirst || !this.focusSelectedOptionOnOpen || selectedValues.length === 0) {
return;
}

Expand Down Expand Up @@ -1887,7 +1889,7 @@ export class VirtualSelect {
const { getString } = Utils;
const secureText = this.secureText.bind(this);

const newOption = {
return {
index: data.index,
value: secureText(getString(data.value)),
label: secureText(getString(data.label)),
Expand All @@ -1897,8 +1899,6 @@ export class VirtualSelect {
isNew: data.isNew || false,
isVisible: true,
};

return newOption;
}

getNewOption() {
Expand Down Expand Up @@ -2179,11 +2179,9 @@ export class VirtualSelect {
DomUtils.removeClass(this.$allWrappers, 'focused');
this.removeOptionFocus();

if (!isSilent) {
if (this.isPopupActive) {
DomUtils.removeClass(this.$body, 'vscomp-popup-active');
this.isPopupActive = false;
}
if (!isSilent && this.isPopupActive) {
DomUtils.removeClass(this.$body, 'vscomp-popup-active');
this.isPopupActive = false;
}

DomUtils.addClass(this.$allWrappers, 'closed');
Expand Down Expand Up @@ -2557,6 +2555,7 @@ export class VirtualSelect {
const isAllSelected = typeof isSelected === 'boolean' ? isSelected : this.isAllGroupOptionsSelected(groupIndex);

this.toggleGroupTitleCheckbox($group, isAllSelected);
this.toggleGroupTitleProp(groupIndex, isAllSelected);
}

toggleGroupTitleProp(groupIndex, isSelected) {
Expand Down Expand Up @@ -2751,10 +2750,8 @@ export class VirtualSelect {
const { description, alias } = data;
let isVisible = searchByStartsWith ? label.startsWith(searchValue) : label.indexOf(searchValue) !== -1;

if (data.isGroupTitle) {
if (!searchGroup || !isVisible) {
isVisible = visibleOptionGroupsMapping[data.index];
}
if (data.isGroupTitle && (!searchGroup || !isVisible)) {
isVisible = visibleOptionGroupsMapping[data.index];
}

if (!searchByStartsWith && alias && !isVisible) {
Expand Down
1 change: 1 addition & 0 deletions src/virtual-select.types.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* @property {string} [tooltipAlignment=center] CSS Text alignment for tooltip
* @property {string} [tooltipMaxWidth='300px'] CSS max width for tooltip
* @property {boolean} [showSelectedOptionsFirst=false] Show selected options at the top of the dropbox
* @property {boolean} [focusSelectedOptionOnOpen=true] Scroll selected option to viewport on dropbox open
* @property {string} [name] Name attribute for hidden input
* @property {boolean} [keepAlwaysOpen] Keep dropbox always open with fixed height
* @property {number} [maxValues=0] Maximum no.of options allowed to choose in multiple select
Expand Down

0 comments on commit 91ec18e

Please sign in to comment.