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

visibleIndex same as index? #362

Open
alvarotrigo opened this issue Oct 31, 2024 · 1 comment
Open

visibleIndex same as index? #362

alvarotrigo opened this issue Oct 31, 2024 · 1 comment

Comments

@alvarotrigo
Copy link

alvarotrigo commented Oct 31, 2024

For some reason the visible index is always the same as the index on the data coming from labelRenderer and sampleLabelRenderer.

Shouldn't one of those values reflect the value of the dropdown item on the DOM?

Demo here (Scroll until the last item on the list)
https://jsfiddle.net/1be6ps5g/

image

Code for reproduction:

VirtualSelect.init({
 ele: '#sample-select',
  options: [
    { label: 'Options 1', value: '1' },
    { label: 'Options 2', value: '2' },
    { label: 'Options 3', value: '3' },
    { label: 'Options 1', value: '1' },
    { label: 'Options 2', value: '2' },
    { label: 'Options 3', value: '3' },
    { label: 'Options 1', value: '1' },
    { label: 'Options 2', value: '2' },
    { label: 'Options 3', value: '3' },
    { label: 'Options 1', value: '1' },
    { label: 'Options 2', value: '2' },
    { label: 'Options 3', value: '3' },
    { label: 'Options 1', value: '1' },
    { label: 'Options 2', value: '2' },
    { label: 'Options 3', value: '3' },
    { label: 'Options 1', value: '1' },
    { label: 'Options 2', value: '2' },
    { label: 'Options 3', value: '3' },
    { label: 'Options 1', value: '1' },
    { label: 'Options 2', value: '2' },
    { label: 'Options 3', value: '3' },
    { label: 'Slabo 27px', value: '1' },
    { label: 'Chokokutai', value: '2' },
    { label: 'Rubik Wet Paint', value: '3' },
  ],
  labelRenderer: sampleLabelRenderer,
  selectedLabelRenderer: sampleLabelRenderer
});

function sampleLabelRenderer(data) {

  console.log(data);

  return `${data.label}`;
}

@alvarotrigo
Copy link
Author

As a workaround I'm forced to do this now:

function sampleLabelRenderer(data) {
     var optionItem = document.querySelector('.vscomp-option-text[data-tooltip="'+data.label+'"]').parentNode;
     var domIndex = Array.prototype.indexOf.call(document.querySelectorAll('.vscomp-option'), optionItem.parentNode);
     
     console.log(domIndex);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant