Skip to content

Commit 34cb4e2

Browse files
committed
Add search results status element
1 parent 7387f91 commit 34cb4e2

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/plugins/search/component.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ function style() {
2121
align-items: center;
2222
}
2323
24+
.search .results-status:not(:empty) {
25+
margin-top: 10px;
26+
font-size: smaller;
27+
}
28+
2429
.search .results-panel {
2530
display: none;
2631
}
@@ -122,6 +127,7 @@ function tpl(defaultValue = '') {
122127
</svg>
123128
</div>
124129
</div>
130+
<div class="results-status" aria-live="polite"></div>
125131
<div class="results-panel"></div>
126132
`;
127133
const el = Docsify.dom.create('div', html);
@@ -137,12 +143,14 @@ function doSearch(value) {
137143
const $panel = Docsify.dom.find($search, '.results-panel');
138144
const $clearBtn = Docsify.dom.find($search, '.clear-button');
139145
const $sidebarNav = Docsify.dom.find('.sidebar-nav');
146+
const $status = Docsify.dom.find('div.search .results-status');
140147
const $appName = Docsify.dom.find('.app-name');
141148

142149
if (!value) {
143150
$panel.classList.remove('show');
144151
$clearBtn.classList.remove('show');
145152
$panel.innerHTML = '';
153+
$status.textContent = '';
146154

147155
if (options.hideOtherSidebarContent) {
148156
$sidebarNav && $sidebarNav.classList.remove('hide');
@@ -169,6 +177,8 @@ function doSearch(value) {
169177
$panel.classList.add('show');
170178
$clearBtn.classList.add('show');
171179
$panel.innerHTML = html || /* html */ `<p class="empty">${NO_DATA_TEXT}</p>`;
180+
$status.textContent = `Found ${matches.length} results`;
181+
172182
if (options.hideOtherSidebarContent) {
173183
$sidebarNav && $sidebarNav.classList.add('hide');
174184
$appName && $appName.classList.add('hide');

0 commit comments

Comments
 (0)