@smilodon/core 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +31 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +31 -13
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.umd.js +31 -13
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1914,26 +1914,44 @@
|
|
|
1914
1914
|
return;
|
|
1915
1915
|
const target = this._config.scrollToSelected.multiSelectTarget;
|
|
1916
1916
|
const indices = Array.from(this._state.selectedIndices).sort((a, b) => a - b);
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1917
|
+
// For multi-select, find the closest selected item to the current scroll position
|
|
1918
|
+
let targetIndex;
|
|
1919
|
+
if (this._config.selection.mode === 'multi' && indices.length > 1) {
|
|
1920
|
+
// Calculate which selected item is closest to the center of the viewport
|
|
1921
|
+
const dropdownRect = this._dropdown.getBoundingClientRect();
|
|
1922
|
+
const viewportCenter = this._dropdown.scrollTop + (dropdownRect.height / 2);
|
|
1923
|
+
// Find the selected item closest to viewport center
|
|
1924
|
+
let closestIndex = indices[0];
|
|
1925
|
+
let closestDistance = Infinity;
|
|
1926
|
+
for (const index of indices) {
|
|
1927
|
+
const optionId = `${this._uniqueId}-option-${index}`;
|
|
1928
|
+
const option = this._optionsContainer.querySelector(`[id="${optionId}"]`);
|
|
1929
|
+
if (option) {
|
|
1930
|
+
const optionTop = option.offsetTop;
|
|
1931
|
+
const distance = Math.abs(optionTop - viewportCenter);
|
|
1932
|
+
if (distance < closestDistance) {
|
|
1933
|
+
closestDistance = distance;
|
|
1934
|
+
closestIndex = index;
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
targetIndex = closestIndex;
|
|
1939
|
+
}
|
|
1940
|
+
else {
|
|
1941
|
+
// For single select or only one selected item, use the configured target
|
|
1942
|
+
targetIndex = target === 'first' ? indices[0] : indices[indices.length - 1];
|
|
1943
|
+
}
|
|
1944
|
+
// Find and scroll to the target option
|
|
1920
1945
|
const optionId = `${this._uniqueId}-option-${targetIndex}`;
|
|
1921
|
-
// We need to search in shadow root or options container
|
|
1922
|
-
// Since options are custom elements, we can find them by ID if we set it (we do)
|
|
1923
|
-
// But wait, we set ID on the element instance, but is it in the DOM?
|
|
1924
|
-
// If filtered out, it won't be in the DOM.
|
|
1925
|
-
// If we are searching, we might not want to scroll to selected if it's not visible
|
|
1926
|
-
// But if we just opened the dropdown, we usually want to see the selected item.
|
|
1927
|
-
// If the selected item is filtered out, we can't scroll to it.
|
|
1928
|
-
// Try to find the element in the options container
|
|
1929
|
-
// Note: querySelector on shadowRoot works if we set the ID attribute
|
|
1930
|
-
// In _renderOptions we set: option.id = ...
|
|
1931
1946
|
const option = this._optionsContainer.querySelector(`[id="${optionId}"]`);
|
|
1932
1947
|
if (option) {
|
|
1948
|
+
// Use smooth scrolling with center alignment for better UX
|
|
1933
1949
|
option.scrollIntoView({
|
|
1934
1950
|
block: this._config.scrollToSelected.block || 'center',
|
|
1935
1951
|
behavior: 'smooth',
|
|
1936
1952
|
});
|
|
1953
|
+
// Also set it as active for keyboard navigation
|
|
1954
|
+
this._setActive(targetIndex);
|
|
1937
1955
|
}
|
|
1938
1956
|
}
|
|
1939
1957
|
async _loadMoreItems() {
|