mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-10 07:55:24 +02:00
sidebar search class added
This commit is contained in:
parent
5cc520ba29
commit
8a865383fa
1 changed files with 5 additions and 9 deletions
|
@ -15,7 +15,9 @@ export default class SidebarSearch {
|
||||||
static get CSS() {
|
static get CSS() {
|
||||||
return {
|
return {
|
||||||
sectionHidden: 'docs-sidebar__section--hidden',
|
sectionHidden: 'docs-sidebar__section--hidden',
|
||||||
|
sectionTitle: 'docs-sidebar__section-title',
|
||||||
sectionTitleSelected: 'docs-sidebar__section-title--selected',
|
sectionTitleSelected: 'docs-sidebar__section-title--selected',
|
||||||
|
sectionList: 'docs-sidebar__section-list',
|
||||||
sectionListItem: 'docs-sidebar__section-list-item',
|
sectionListItem: 'docs-sidebar__section-list-item',
|
||||||
sectionListItemWrapperHidden: 'docs-sidebar__section-list-item-wrapper--hidden',
|
sectionListItemWrapperHidden: 'docs-sidebar__section-list-item-wrapper--hidden',
|
||||||
sectionListItemSlelected: 'docs-sidebar__section-list-item--selected',
|
sectionListItemSlelected: 'docs-sidebar__section-list-item--selected',
|
||||||
|
@ -62,10 +64,10 @@ export default class SidebarSearch {
|
||||||
this.search.addEventListener('input', e => {
|
this.search.addEventListener('input', e => {
|
||||||
e.stopImmediatePropagation();
|
e.stopImmediatePropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.search(e.target.value);
|
this.filterSections(e.target.value);
|
||||||
});
|
});
|
||||||
// Initialize the search results.
|
// Initialize the search results.
|
||||||
this.search('');
|
this.filterSections('');
|
||||||
|
|
||||||
// Add event listener for keyboard events.
|
// Add event listener for keyboard events.
|
||||||
this.search.addEventListener('keydown', e => this.handleKeyboardEventOnSearch(e));
|
this.search.addEventListener('keydown', e => this.handleKeyboardEventOnSearch(e));
|
||||||
|
@ -189,12 +191,7 @@ export default class SidebarSearch {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
filterSections(searchValue) {
|
||||||
* Search for items in the sidebar.
|
|
||||||
*
|
|
||||||
* @param {InputEvent} searchValue - search value.
|
|
||||||
*/
|
|
||||||
search(searchValue) {
|
|
||||||
// remove selection from previous search results.
|
// remove selection from previous search results.
|
||||||
if (this.selectedSearchResultIndex) {
|
if (this.selectedSearchResultIndex) {
|
||||||
const { element, type } = this.searchResults[this.selectedSearchResultIndex];
|
const { element, type } = this.searchResults[this.selectedSearchResultIndex];
|
||||||
|
@ -212,7 +209,6 @@ export default class SidebarSearch {
|
||||||
}
|
}
|
||||||
// empty search results.
|
// empty search results.
|
||||||
this.searchResults = [];
|
this.searchResults = [];
|
||||||
|
|
||||||
// match search value with sidebar sections.
|
// match search value with sidebar sections.
|
||||||
this.sections.forEach(section => {
|
this.sections.forEach(section => {
|
||||||
// match with section title.
|
// match with section title.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue