Skip to content

Commit

Permalink
Merge pull request #1405 from Infineon/991-multiselect-when-select-is…
Browse files Browse the repository at this point in the history
…-set-to-true-on-an-option-its-checkbox-remains-unchecked-on-the-menu

991 multiselect when select is set to true on an option its checkbox remains unchecked on the menu
  • Loading branch information
tishoyanchev committed Aug 2, 2024
2 parents ef08118 + 47c6808 commit f220183
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "24.3.0",
"version": "24.3.1--canary.1405.fc5d5fdb6f84b4aa808b4927beba383ce6e7f5e7.0",
"command": {
"publish": {
"verifyAccess": false
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/components-angular/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "components-angular",
"version": "24.3.0",
"version": "24.3.1--canary.1405.fc5d5fdb6f84b4aa808b4927beba383ce6e7f5e7.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand All @@ -26,7 +26,7 @@
"@angular/platform-browser": "^17.3.3",
"@angular/platform-browser-dynamic": "^17.3.3",
"@angular/router": "^17.3.3",
"@infineon/infineon-design-system-angular": "^24.3.0",
"@infineon/infineon-design-system-angular": "^24.3.1--canary.1405.fc5d5fdb6f84b4aa808b4927beba383ce6e7f5e7.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.4"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@infineon/infineon-design-system-angular",
"version": "24.3.0",
"version": "24.3.1--canary.1405.fc5d5fdb6f84b4aa808b4927beba383ce6e7f5e7.0",
"description": "Infineon design system Stencil web components for Angular",
"author": "Verena Lechner",
"license": "MIT",
Expand All @@ -11,7 +11,7 @@
"@angular/common": "^17.3.3",
"@angular/core": "^17.3.3",
"@infineon/design-system-tokens": "3.3.2",
"@infineon/infineon-design-system-stencil": "^24.3.0"
"@infineon/infineon-design-system-stencil": "^24.3.1--canary.1405.fc5d5fdb6f84b4aa808b4927beba383ce6e7f5e7.0"
},
"dependencies": {
"tslib": "^2.3.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/components-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@infineon/infineon-design-system-react",
"version": "24.3.0",
"version": "24.3.1--canary.1405.fc5d5fdb6f84b4aa808b4927beba383ce6e7f5e7.0",
"description": "Infineon design system Stencil web components for React",
"main": "dist/index.js",
"module": "dist/index.js",
Expand Down Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"@infineon/design-system-tokens": "3.3.2",
"@infineon/infineon-design-system-stencil": "24.3.0"
"@infineon/infineon-design-system-stencil": "24.3.1--canary.1405.fc5d5fdb6f84b4aa808b4927beba383ce6e7f5e7.0"
},
"auto": {
"plugins": [
Expand Down
4 changes: 2 additions & 2 deletions packages/components-vue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@infineon/infineon-design-system-vue",
"version": "24.3.0",
"version": "24.3.1--canary.1405.fc5d5fdb6f84b4aa808b4927beba383ce6e7f5e7.0",
"description": "Infineon design system Stencil web components for Vue",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -31,7 +31,7 @@
},
"dependencies": {
"@infineon/design-system-tokens": "3.3.2",
"@infineon/infineon-design-system-stencil": "24.3.0"
"@infineon/infineon-design-system-stencil": "24.3.1--canary.1405.fc5d5fdb6f84b4aa808b4927beba383ce6e7f5e7.0"
},
"auto": {
"plugins": [
Expand Down
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@infineon/infineon-design-system-stencil",
"version": "24.3.0",
"version": "24.3.1--canary.1405.fc5d5fdb6f84b4aa808b4927beba383ce6e7f5e7.0",
"private": false,
"description": "Infineon design system Stencil web components",
"homepage": "https://infineon.github.io/infineon-design-system-stencil",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,29 @@ const options = [
},
];

const longOptions = [];
for (let i=1; i<=50; i++) {
let children = undefined;
if (i % 3 == 0) {
children = [{
"value": `${i}.1`,
"label": `Option ${i}.1`,
"selected": i % 2 == 0 ? true : false
},{
"value": `${i}.2`,
"label": `Option ${i}.2`,
"selected": i % 4 == 0 ? true : false
}];
}
longOptions.push({
"value": i,
"label": `Option ${i}`,
"selected": i % 2 == 0 ? true : false,
"children": children
})
}


export default {
title: 'Components/Select/Multi Select',
// tags: ['autodocs'],
Expand Down Expand Up @@ -120,7 +143,7 @@ export default {
},
};

const DefaultTemplate = args => {
const Template = args => {
const template = `<ifx-multiselect
options='${JSON.stringify(args.options)}'
batch-size='${args.batchSize}'
Expand All @@ -142,7 +165,14 @@ const DefaultTemplate = args => {
return template;
};

export const Default = DefaultTemplate.bind({});
export const Default = Template.bind({});
Default.args = {
options: options,
};

export const WithLazyLoading = Template.bind({});
WithLazyLoading.args = {
options: longOptions,
batchSize: 5,
maxItemCount: undefined
};
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class Multiselect {
@Prop() showSearch: boolean = true;
@Prop() showSelectAll: boolean = true;
@State() optionCount: number = 0; // number of all options (leaves of the tree)
@State() optionsProcessed: boolean = false; // flag whether options have already been counted, intial selections saved


@Event() ifxSelect: EventEmitter;
Expand Down Expand Up @@ -101,19 +102,63 @@ export class Multiselect {
console.error('Unexpected value for options:', this.options);
}

this.optionCount = this.countOptions(allOptions);

if (!this.optionsProcessed) {
this.optionCount = this.countOptions(allOptions);
const initiallySelected = this.collectSelectedOptions(allOptions);
const initallySelectedNotInState = initiallySelected.filter(init => !this.persistentSelectedOptions.some(opt => opt.value == init.value));
this.persistentSelectedOptions = [...this.persistentSelectedOptions, ...initallySelectedNotInState];
this.optionsProcessed = true;
}

// Slice the options array based on startIndex and count
const slicedOptions = allOptions.slice(startIndex, startIndex + count);
return slicedOptions;
}

// Update the state for initially selected options, if needed
if (startIndex === 0) { // Assuming you want to do this only for the first batch
const initiallySelected = slicedOptions.filter(option => option.selected);
const initallyAndNotAdded = initiallySelected.filter(init => !this.persistentSelectedOptions.some(opt => opt.value == init.value));
this.persistentSelectedOptions = [...this.persistentSelectedOptions, ...initallyAndNotAdded];
/**
* Collects and returns all options that are selected.
* When the parent is selected, then the value of the children will be overriden with selected as well.
* It will only collect the leaves of the tree.
*
* @param options A list of options.
* @returns A list with all selected options
*/
private collectSelectedOptions(options: Option[]): Option[] {
let selectedOptions: Option[] = [];

for (const option of options) {
if (option.selected) {
if (option.children && option.children.length > 0) {
// if parent is selected, then select all child options
selectedOptions = selectedOptions.concat(this.collectLeafOptions(option.children));
} else {
selectedOptions.push(option);
}
} else {
if (option.children && option.children.length > 0) {
selectedOptions = selectedOptions.concat(this.collectSelectedOptions(option.children));
}
}
}
return selectedOptions;
}

return slicedOptions;
/**
* Collects all leaf children options.
*
* @param option A list with all leaf-children.
*/
private collectLeafOptions(children: Option[]): Option[] {
let leafOptions = [];

for (const child of children) {
if (child.children && child.children.length > 0) {
leafOptions = leafOptions.concat(this.collectLeafOptions(child.children));
} else {
leafOptions.push(child);
}
}
return leafOptions;
}

/**
Expand Down

0 comments on commit f220183

Please sign in to comment.