Fix combobox bugs

- size and position is recalculated for each
  update so that it works even if input
  isn't rendered when combobox is called
- adds caret differently, for same reason as above
- adds combobox to body to prevent scrolling issues
This commit is contained in:
Ansis Brammanis
2013-02-18 16:56:11 -05:00
parent f99a80b52f
commit 876a406e70
2 changed files with 22 additions and 23 deletions

View File

@@ -7,6 +7,7 @@ body {
padding:0;
min-width: 768px;
color:#222;
overflow: hidden;
/* text-rendering: optimizeLegibility; */
-webkit-font-smoothing: subpixel-antialiased;
}
@@ -1546,15 +1547,11 @@ div.combobox {
border-top: 0;
}
.combobox-carat::after {
display:block;
content: '';
.combobox-carat {
margin-left: -15px;
margin-right: 5px;
display:inline-block;
cursor:url(../img/cursor-pointer.png) 6 1, auto;
position: absolute;
right: 10px;
top: 5px;
height: 0;
width: 0;
border-top: 5px solid #ccc;
border-left: 5px solid transparent;
border-right: 5px solid transparent;

View File

@@ -12,34 +12,34 @@ d3.combobox = function() {
};
var typeahead = function(selection) {
var idx = -1,
rect = selection.select('input')
.node()
.getBoundingClientRect();
var idx = -1;
input = selection.select('input');
container = selection
container = d3.select(document.body)
.insert('div', ':first-child')
.attr('class', 'combobox')
.style({
position: 'absolute',
display: 'none',
left: '0px',
width: rect.width + 'px',
top: rect.height + 'px'
left: '0px'
});
selection
.insert('a', ':first-child')
selection.append('a', selection.select('input'))
.attr('class', 'combobox-carat')
.style({
position: 'absolute',
left: rect.width + 'px',
top: '0px'
})
.on('mousedown', stop)
.on('click', click);
function updateSize() {
var rect = selection.select('input')
.node()
.getBoundingClientRect();
container.style({
'left': rect.left + 'px',
'width': rect.width + 'px',
'top': rect.height + rect.top + 'px'
});
}
function stop() {
// prevent the form element from blurring. it blurs
// on mousedown
@@ -156,6 +156,8 @@ d3.combobox = function() {
if (data.length) show();
else hide();
updateSize();
var options = container
.selectAll('a.combobox-option')
.data(data, function(d) { return d.value; });