Press return to choose the first list item in search-to-add field

This commit is contained in:
Quincy Morgan
2019-03-02 16:52:24 -05:00
parent 971b901b21
commit ad58779d09
3 changed files with 16 additions and 3 deletions

View File

@@ -674,6 +674,10 @@ button.add-note svg.icon {
top: 0;
left: 0;
}
.search-add .list-item button.choose:hover,
.search-add .list-item button.choose:focus {
background: #E6ECFF;
}
.search-add .list-item button.choose.disabled {
background-color: #ececec;
}

View File

@@ -91,7 +91,7 @@ export function uiPresetList(context) {
var value = search.property('value');
if (d3_event.keyCode === 13 && value.length) {
list.selectAll('.preset-list-item:first-child')
.each(function(d) { d.choose.call(d3_select(this).node()); });
.each(function(d) { d.choose.call(this); });
}
}

View File

@@ -42,9 +42,18 @@ export function uiSearchAdd(context) {
.attr('placeholder', t('modes.add_feature.title'))
.attr('type', 'search')
.call(utilNoAuto)
.on('keypress', function() {
// enter/return
if (d3_event.keyCode === 13) {
popover.selectAll('.list > .list-item:first-child button.choose')
.each(function(d) { d.choose.call(this); });
d3_event.preventDefault();
d3_event.stopPropagation();
}
})
.on('focus', function() {
search.attr('focusing', true);
search.node().setSelectionRange(0, search.property('value').length);
search.attr('focusing', true);
popover.classed('hide', false);
})
.on('blur', function() {
@@ -52,8 +61,8 @@ export function uiSearchAdd(context) {
})
.on('click', function() {
if (search.attr('focusing')) {
search.attr('focusing', null);
search.node().setSelectionRange(0, search.property('value').length);
search.attr('focusing', null);
d3_event.preventDefault();
d3_event.stopPropagation();
}