Ensure "New Relation..." is always available (fixes #2066)

This commit is contained in:
John Firebaugh
2014-01-03 13:00:36 -08:00
parent a6a6cd77f9
commit 3e2968310b
3 changed files with 17 additions and 2 deletions
+1
View File
@@ -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));
})
+9 -2
View File
@@ -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');
};
+7
View File
@@ -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());