dipson88 / treeselectjs

Treeselect on vanilla JS
MIT License
83 stars 15 forks source link

Expand #115

Open gpibarra opened 3 weeks ago

gpibarra commented 3 weeks ago

The following code

const options = [
  {
    name: 'England',
    value: 1,
    children: [
      {
        name: 'London',
        value: 2,
        children: [
          {
            name: 'Chelsea',
            value: 3,
            children: []
          },
          {
            name: 'West End',
            value: 4,
            children: []
          }
        ]
      },
      {
        name: 'Brighton',
        value: 5,
        children: []
      }
    ]
  },
  {
    name: 'France',
    value: 6,
    children: [
      {
        name: 'Paris',
        value: 7,
        children: []
      },
      {
        name: 'Lyon',
        value: 8,
        children: []
      }
    ]
  }
]

const className = '.treeselect-demo-single-select'

export const runSingleSelectExample = (Treeselect) => {
  const domElement = document.querySelector(className)
  const treeselect = new Treeselect({
    parentHtmlContainer: domElement,
    value: 4,
    options: options,
    isSingleSelect: true,
    expandSelected: true,
    // isIndependentNodes: false,
    showTags: false
  })

  treeselect.srcElement.addEventListener('input', (e) => {
    console.log('singleSelect: Selected value ', e.detail)
  })
}

or in app/examples/singleSelect.js add the option expandSelected: true,

The selected option is not expanded, in In the example, the selected value is 4-WestEnd which is a child of 1-England > 2-London.

I imagine that the return in the file src/list/helpers/listCheckStateHelper.ts:16 should not be , but changing that has some side effects (for example isIndependentNodes), what would be the best way to solve it?