Skip to content

Commit affa35c

Browse files
committed
feat(select): Add toggle button and remove force open in editor option (WW-3773)
1 parent 712db97 commit affa35c

File tree

2 files changed

+42
-39
lines changed

2 files changed

+42
-39
lines changed

src/wwElement_Select.vue

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,13 @@ export default {
106106
// eslint-disable-next-line no-unreachable
107107
return false;
108108
});
109-
const forceOpenInEditor = computed(() => {
110-
/* wwEditor:start */
111-
return props.wwEditorState.sidepanelContent.forceOpenInEditor;
112-
/* wwEditor:end */
113-
return false;
114-
});
109+
const forceOpenInEditor = ref(false);
115110
116111
const appDivRef = shallowRef(wwLib.getFrontDocument().querySelector('#app'));
117112
118113
const selectType = computed(() => props.content.selectType);
119114
const initValue = computed(() =>
120-
selectType.value === 'single' ? props.content.initValueSingle ?? null : props.content.initValueMulti || []
115+
selectType.value === 'single' ? (props.content.initValueSingle ?? null) : props.content.initValueMulti || []
121116
);
122117
const { value: variableValue, setValue } = wwLib.wwVariable.useComponentVariable({
123118
uid: props.uid,
@@ -281,7 +276,7 @@ export default {
281276
}
282277
} else {
283278
const currentValue = Array.isArray(variableValue.value) ? [...variableValue.value] : [];
284-
279+
285280
// Find the index with proper object comparison if needed
286281
let valueIndex = -1;
287282
if (typeof value === 'object' && value !== null) {
@@ -321,7 +316,7 @@ export default {
321316
shouldCloseDropdown.value = false;
322317
323318
const currentValue = Array.isArray(variableValue.value) ? [...variableValue.value] : [];
324-
319+
325320
// Find index using the utility function
326321
const valueIndex = findValueIndex(currentValue, valueToRemove);
327322
@@ -440,7 +435,7 @@ export default {
440435
option,
441436
])
442437
);
443-
438+
444439
// Format option for display
445440
const formatOption = opt => ({
446441
value: resolveMappingFormula(toValue(mappingValue), opt) ?? opt.value,
@@ -450,33 +445,31 @@ export default {
450445
});
451446
452447
// Find option by value using the utility function
453-
const findOptionByValue = (value) => {
448+
const findOptionByValue = value => {
454449
// Use the utility function to find an entry with matching key
455-
const entry = Array.from(_optionsMap.entries()).find(([key, _]) =>
456-
areValuesEqual(key, value)
457-
);
450+
const entry = Array.from(_optionsMap.entries()).find(([key, _]) => areValuesEqual(key, value));
458451
return entry ? entry[1] : null;
459452
};
460-
453+
461454
// Handle single select
462455
if (selectType.value === 'single') {
463456
const option = findOptionByValue(variableValue.value);
464457
return option ? formatOption(option) : null;
465-
}
458+
}
466459
// Handle multiple select
467460
else {
468461
const selectedValues = Array.isArray(variableValue.value) ? variableValue.value : [];
469462
return selectedValues.map(value => {
470463
const option = findOptionByValue(value);
471-
464+
472465
if (!option) {
473466
return {
474467
value,
475468
isInOptions: false,
476469
info: 'This value is not in the defined options',
477470
};
478471
}
479-
472+
480473
return formatOption(option);
481474
});
482475
}
@@ -500,19 +493,25 @@ export default {
500493
501494
// Initialize passive event support detection
502495
try {
503-
window.addEventListener("test", null, Object.defineProperty({}, 'passive', {
504-
get: function () { supportsPassive = true; }
505-
}));
506-
} catch(e) {}
496+
window.addEventListener(
497+
'test',
498+
null,
499+
Object.defineProperty({}, 'passive', {
500+
get: function () {
501+
supportsPassive = true;
502+
},
503+
})
504+
);
505+
} catch (e) {}
507506
508507
wheelOpt = supportsPassive ? { passive: false } : false;
509508
wheelEvent = 'onwheel' in document.createElement('div') ? 'wheel' : 'mousewheel';
510509
511-
const preventDefault = (e) => {
510+
const preventDefault = e => {
512511
e.preventDefault();
513512
};
514513
515-
const preventDefaultForScrollKeys = (e) => {
514+
const preventDefaultForScrollKeys = e => {
516515
const keys = { 37: 1, 38: 1, 39: 1, 40: 1 };
517516
if (keys[e.keyCode]) {
518517
preventDefault(e);
@@ -865,6 +864,9 @@ export default {
865864
this.resetLastTriggerComponentAction();
866865
this.resetSearch();
867866
},
867+
toggleForceOpenInEditor() {
868+
this.forceOpenInEditor = !this.forceOpenInEditor;
869+
},
868870
},
869871
};
870872
</script>

ww-config.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export default {
138138
],
139139
],
140140
customSettingsPropertiesOrder: [
141-
'forceOpenInEditor',
141+
'toggleSelect',
142142
'showEmptyStateInEditor',
143143
'choices',
144144
'mappingLabel',
@@ -196,11 +196,6 @@ export default {
196196
action: 'actionCloseDropdown',
197197
args: [],
198198
},
199-
{
200-
label: 'Toggle',
201-
action: 'actionToggleDropdown',
202-
args: [],
203-
},
204199
{
205200
label: 'Set value',
206201
action: 'actionUpdateValue',
@@ -233,8 +228,22 @@ export default {
233228
action: 'actionResetSearch',
234229
args: [],
235230
},
231+
{
232+
label: 'Toggle force open in editor',
233+
action: 'toggleForceOpenInEditor',
234+
args: [],
235+
},
236236
],
237237
properties: {
238+
toggleSelect: {
239+
type: 'Button',
240+
editorOnly: true,
241+
section: 'settings',
242+
options: {
243+
text: { en: 'Toggle' },
244+
action: 'toggleForceOpenInEditor',
245+
},
246+
},
238247
// >>>>>>>>>>> SELECT <<<<<<<<<<
239248
choices: {
240249
label: {
@@ -429,13 +438,6 @@ export default {
429438
/* wwEditor:end */
430439
section: 'settings',
431440
},
432-
forceOpenInEditor: {
433-
label: { en: 'Force open in editor' },
434-
type: 'OnOff',
435-
defaultValue: false,
436-
editorOnly: true,
437-
section: 'settings',
438-
},
439441
initialState: {
440442
label: { en: 'Initial state' },
441443
type: 'TextSelect',
@@ -808,8 +810,7 @@ export default {
808810
bindable: true,
809811
responsive: true,
810812
propertyHelp: {
811-
tooltip:
812-
'This should be disabled in some edge cases like in popups, datagrid, etc.',
813+
tooltip: 'This should be disabled in some edge cases like in popups, datagrid, etc.',
813814
},
814815
bindingValidation: {
815816
type: 'boolean',

0 commit comments

Comments
 (0)