mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 05:30:35 +02:00
Ensure "New Relation..." is always available (fixes #2066)
This commit is contained in:
@@ -152,6 +152,7 @@ iD.ui.RawMembershipEditor = function(context) {
|
||||
.attr('type', 'text')
|
||||
.attr('class', 'member-entity-input')
|
||||
.call(d3.combobox()
|
||||
.minItems(1)
|
||||
.fetcher(function(value, callback) {
|
||||
callback(relations(value));
|
||||
})
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
d3.combobox = function() {
|
||||
var event = d3.dispatch('accept'),
|
||||
data = [],
|
||||
suggestions = [];
|
||||
suggestions = [],
|
||||
minItems = 2;
|
||||
|
||||
var fetcher = function(val, cb) {
|
||||
cb(data.filter(function(d) {
|
||||
@@ -192,7 +193,7 @@ d3.combobox = function() {
|
||||
}
|
||||
|
||||
function render() {
|
||||
if (suggestions.length > 1 && document.activeElement === input.node()) {
|
||||
if (suggestions.length >= minItems && document.activeElement === input.node()) {
|
||||
show();
|
||||
} else {
|
||||
hide();
|
||||
@@ -258,5 +259,11 @@ d3.combobox = function() {
|
||||
return combobox;
|
||||
};
|
||||
|
||||
combobox.minItems = function(_) {
|
||||
if (!arguments.length) return minItems;
|
||||
minItems = _;
|
||||
return combobox;
|
||||
};
|
||||
|
||||
return d3.rebind(combobox, event, 'on');
|
||||
};
|
||||
|
||||
@@ -95,6 +95,13 @@ describe("d3.combobox", function() {
|
||||
expect(body.selectAll('.combobox-option').size()).to.equal(0);
|
||||
});
|
||||
|
||||
it("shows menu on focus if it would contain at least minItems items", function() {
|
||||
combobox.minItems(1);
|
||||
input.property('value', 'f').call(combobox.data(data));
|
||||
input.node().focus();
|
||||
expect(body.selectAll('.combobox-option').size()).to.equal(1);
|
||||
});
|
||||
|
||||
it("shows all entries when clicking on the caret", function() {
|
||||
input.property('value', 'foo').call(combobox.data(data));
|
||||
happen.mousedown(body.selectAll('.combobox-caret').node());
|
||||
|
||||
Reference in New Issue
Block a user