Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open combobox if anywhere on box clicked... #5636

Merged
merged 2 commits into from
Dec 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions css/80_app.css
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,7 @@ div.combobox {
margin-left: -30px;
vertical-align: top;
cursor: pointer;
pointer-events: none;
}
[dir='rtl'] .combobox-caret {
margin-left: 0;
Expand Down
34 changes: 17 additions & 17 deletions modules/ui/combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ export function uiCombobox(context, klass) {
.on('keydown.typeahead', keydown)
.on('keyup.typeahead', keyup)
.on('input.typeahead', change)
.on('mousedown', mousedown)
.each(addCaret);


function addCaret() {
var parent = this.parentNode;
var sibling = this.nextSibling;
Expand All @@ -65,22 +65,6 @@ export function uiCombobox(context, klass) {
.attr('class', 'combobox-caret')
.merge(caret);

caret
.on('mousedown', function () {
// prevent the form element from blurring. it blurs on mousedown
d3_event.stopPropagation();
d3_event.preventDefault();
var combo = container.selectAll('.combobox');
if (combo.empty()) {
input.node().focus();
fetch('', function() {
show();
render();
});
} else {
hide();
}
});
}


Expand Down Expand Up @@ -205,6 +189,22 @@ export function uiCombobox(context, klass) {
}


function mousedown() {
// prevent the form element from blurring. it blurs on mousedown
d3_event.stopPropagation();
d3_event.preventDefault();
var combo = container.selectAll('.combobox');
if (combo.empty()) {
input.node().focus();
fetch('', function() {
show();
render();
});
} else {
hide();
}
}

function nav(dir) {
if (!_suggestions.length) return;

Expand Down
6 changes: 3 additions & 3 deletions test/spec/ui/combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('uiCombobox', function() {

it('adds combobox under container', function() {
input.call(combobox.data(data));
body.selectAll('.combobox-caret').dispatch('mousedown');
body.selectAll('.combobox-input').dispatch('mousedown');
expect(d3.select('.id-container > div.combobox').nodes().length).to.equal(1);
});

Expand All @@ -106,14 +106,14 @@ describe('uiCombobox', function() {

it('shows all entries when clicking on the caret', function() {
input.property('value', 'foobar').call(combobox.data(data));
body.selectAll('.combobox-caret').dispatch('mousedown');
body.selectAll('.combobox-input').dispatch('mousedown');
expect(body.selectAll('.combobox-option').size()).to.equal(5);
expect(body.selectAll('.combobox-option').text()).to.equal('foobar');
});

it('is initially shown with no selection', function() {
input.call(combobox.data(data));
body.selectAll('.combobox-caret').dispatch('mousedown');
body.selectAll('.combobox-input').dispatch('mousedown');
expect(body.selectAll('.combobox-option.selected').size()).to.equal(0);
});

Expand Down