Skip to content

Commit 7f6c921

Browse files
committed
[UPD] accessibility
1 parent c09ac0a commit 7f6c921

File tree

2 files changed

+40
-22
lines changed

2 files changed

+40
-22
lines changed

examples/style.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ h2 {
173173
}
174174

175175
#map button {
176-
outline: none;
176+
/* outline: none; */
177177
}
178178

179179
.ol-attribution img {

src/control/Search.js

+39-21
Original file line numberDiff line numberDiff line change
@@ -105,33 +105,44 @@ var ol_control_Search = class olcontrolSearch extends ol_control_Control {
105105
// move up/down
106106
if (e.key == 'ArrowDown' || e.key == 'ArrowUp' || e.key == 'Down' || e.key == 'Up') {
107107
if (li) {
108-
li.classList.remove("select");
109-
li = (/Down/.test(e.key)) ? li.nextElementSibling : li.previousElementSibling;
110-
if (li)
111-
li.classList.add("select");
108+
var newli = (/Down/.test(e.key)) ? li.nextElementSibling : li.previousElementSibling;
109+
if (newli && !newli.classList.contains('copy')) {
110+
li.classList.remove("select");
111+
newli.classList.add("select");
112+
input.value = newli.innerText;
113+
}
112114
} else {
113-
element.querySelector("ul.autocomplete li").classList.add("select");
115+
li = element.querySelector("ul.autocomplete li")
116+
li.classList.add("select");
117+
input.value = li.innerText;
114118
}
115119
}
116120

117121
// Clear input
118-
else if (e.type == 'input' && !val) {
119-
setTimeout(function () {
120-
self.drawList_();
121-
}, 200);
122+
else if (e.type == 'input') {
123+
if (!val) {
124+
setTimeout(function () {
125+
self.drawList_();
126+
}, 200);
127+
}
128+
if (li) {
129+
input.value = val = '';
130+
li.classList.remove("select");
131+
}
122132
}
123133

124134
// Select in the list
125-
else if (li && (e.type == "search" || e.key == "Enter")) {
126-
if (element.classList.contains("ol-control"))
135+
else if (li && (e.type === "search" || e.key === "Enter")) {
136+
if (element.classList.contains("ol-control")) {
127137
input.blur();
138+
}
128139
li.classList.remove("select");
129140
cur = val;
130141
self._handleSelect(self._list[li.getAttribute("data-search")]);
131142
}
132143

133144
// Search / autocomplete
134-
else if ((e.type == "search" || e.key == 'Enter')
145+
else if ((e.type === "search" || e.key === 'Enter')
135146
|| (cur != val && options.typing >= 0)) {
136147
// current search
137148
cur = val;
@@ -181,6 +192,11 @@ var ol_control_Search = class olcontrolSearch extends ol_control_Control {
181192
element.classList.remove('ol-revers');
182193
}
183194
}.bind(this));
195+
input.addEventListener('keydown', function() {
196+
this.set('reverse', false);
197+
element.classList.remove('ol-collapsed');
198+
element.classList.remove('ol-revers');
199+
}.bind(this))
184200
}
185201
element.appendChild(input);
186202
// Reverse geocode
@@ -189,15 +205,17 @@ var ol_control_Search = class olcontrolSearch extends ol_control_Control {
189205
type: 'button',
190206
class: 'ol-revers',
191207
title: options.reverseTitle || 'click on the map',
192-
click: function () {
193-
if (!this.get('reverse')) {
194-
this.set('reverse', !this.get('reverse'));
195-
input.focus();
196-
element.classList.add('ol-revers');
197-
} else {
198-
this.set('reverse', false);
199-
}
200-
}.bind(this)
208+
on: {
209+
focus: function () {
210+
if (!this.get('reverse')) {
211+
this.set('reverse', !this.get('reverse'));
212+
input.focus();
213+
element.classList.add('ol-revers');
214+
} else {
215+
this.set('reverse', false);
216+
}
217+
}.bind(this)
218+
}
201219
});
202220
element.appendChild(reverse);
203221
}

0 commit comments

Comments
 (0)