Reputation: 2643
I am trying to get a footer toolbar, consisting of two buttons (prev/next) and a selectmenu. How can I make the selectmenu use the full width?
See jsFiddle example for details.
Using a controlgroup makes it look the way I want/need, except that it does not fill the full width. I also experimented with fieldset, navbar, grids, but so far not the wanted result.
<div data-role="controlgroup" data-type="horizontal" id="footerControlgroup" >
<button id="prev" class="ui-btn ui-corner-all ui-icon-carat-l ui-btn-icon-notext ui-mini">Prev</button>
<button id="next" class="ui-btn ui-corner-all ui-icon-carat-r ui-btn-icon-notext ui-mini">Next</button>
<select id="select" data-mini="true">
<option>pick me...</option>
</select>
</div>
Upvotes: 0
Views: 642
Reputation: 2643
Rick pointed me in the right direction, thanks.
Here is the complete solution: jsFiddle.
The key part of the solution:
var select = $("#mySelect");
var cWidth = 0;
select.closest(".ui-controlgroup-controls").children().not(".ui-select")
.each(function() {
cWidth += $(this).outerWidth();
$(this).outerHeight( select.closest(".ui-select").height() +0.5 );
});
select.closest(".ui-select").find(".ui-btn")
.outerWidth( select.closest("[data-role='controlgroup']").width() - cWidth -1);
The tricky parts that it deals with:
In case you are interested: the structure of the jQuery Mobile select menu's:
native select
div data-role=controlgroup
div .ui-controlgroup-controls
button #prev .ui-btn
button #next .ui-btn
div .ui-select
div #<selectId>-button .ui-btn <== adjust width
span <text of first item>
select #<selectId> <-- starting point
custom select
div data-role=controlgroup
div .ui-controlgroup-controls
button #prev .ui-btn
button #next .ui-btn
div .ui-select
a #<selectId>-button .ui-btn <== adjust width
span <text of first item>
select #<selectId> <-- starting point
div #<selectId>-listbox-placeholder
Upvotes: 1
Reputation: 35670
This may get you going:
var next= document.getElementById('next');
var select= document.getElementById('select');
select.style.width=
(select.parentNode.offsetWidth -
next.getBoundingClientRect().right
)+'px';
Upvotes: 1