Combobox idea

172 views
Skip to first unread message

Mat

unread,
Nov 4, 2021, 7:38:55 AM11/4/21
to TiddlyWiki
I just came up with a simple idea for how to create comboboxes. Basically it is an EditTextWidget just before the SelectWidget and the select widget is styled to only show the arrow and both widgets refer to the same field.

Three problems:
1) Editing the field loses focus so only one letter at a time. 
2) When the <option> tag has a value, this is what is shown in the editor.
3) The popup should be pushed to the left but I can't find the css selector. (Attempting to right click on it to inspect it doesn't work.)

Any ideas?

<:-)
__________________________________________________________
Code for you to copy paste, showing two examples including the problems: 

<$edit-text field=selection placeholder={{!!selection}}/>
<$select tiddler='About' field=selection class="select-btn" default={{About!!selection}} >
<option disabled hidden>{{About!!selection}}</option>
<option>one</option>
<option>two</option>
<option>three</option>
</$select>

option with values shows the value rather than the label:<br>
<$edit-text field=selection2 placeholder={{About!!selection2}}/>
<$select tiddler='About' field=selection2 class="select-btn" default={{About!!selection2}} >
<option disabled hidden>{{About!!selection2}}</option>
<option value='cities'>A Tale of Two Cities</option>
<option value='science'>A New Kind of Science</option>
<option value='dice'>The Dice Man</option>
</$select>

<style>
.select-btn {width:19px; margin-left:-4px;}
</style>

Eric Shulman

unread,
Nov 4, 2021, 10:30:09 AM11/4/21
to TiddlyWiki
On Thursday, November 4, 2021 at 4:38:55 AM UTC-7 Mat wrote:
I just came up with a simple idea for how to create comboboxes. Basically it is an EditTextWidget just before the SelectWidget and the select widget is styled to only show the arrow and both widgets refer to the same field.

My `<<edit-list>>` macro initially use a similar approach, but I found that it had too many problems with both interaction and appearance.  I also wanted to support use of inline lists (where the listbox is visible below the input fied), multiple selection (using standard shift-click/ctrl-click interaction), confirmation of input (ok/cancel), progressive filtering (reducing the list choices to only those that contain the current edit field input), and integration with my popup Calendar for selecting and formatting date input (see https://tiddlytools.com/timer.html#TiddlyTools%2FTime%2FCalendar) .

The result still uses an underlying edit-text and select widget, but they are surrounded by a bunch of custom wikitext code to handle lots of options and use-cases.


enjoy,
-e

Mat

unread,
Nov 4, 2021, 11:20:39 AM11/4/21
to TiddlyWiki
Thanks Eric. I also have other ways of achieving the end result, but with the direct editing of currentTiddler fields in TW 5.2.0 I thought I had come across a very simple solution for a simple combobox.

However, some further experimenting shows that the lost focus was easily solved by just removing the placeholder reference to edited field. Not even sure what I was thinking (why should it refer to there?). Also unnecessary with the selectwidget default stuff.
Thus the remaining two problems are:

1) When the <option> tag has a value, this is what is shown in the editor.
2) The popup should be pushed to the left but I can't find the css selector for it! A less elegant workaround is to simply put the (still styled) SelectWidget before the EditTextWidget, so the button is to the left of the editor.



And here's the simplified code. When used you see the problems.

<$edit-text field=selection placeholder="type or select"/>
<$select field=selection class="select-btn" >
<option value='cities'>A Tale of Two Cities</option>
<option value='science'>A New Kind of Science</option>
<option value='dice'>The Dice Man</option>
</$select>

<style>
.select-btn {width:19px; margin-left:-4px;}
</style>

Télumire

unread,
Nov 4, 2021, 3:31:14 PM11/4/21
to TiddlyWiki
Here's the code to push the dropdown in the proper place :

<span class="combobox">

<$select field=selection class="select-btn" >
<option value='cities'>A Tale of Two Cities</option>
<option value='science'>A New Kind of Science</option>
<option value='dice'>The Dice Man</option>
</$select>
<$edit-text field=selection placeholder="type or select"/>
</span>

<style>
.combobox{
position:relative;
display:inline-block;
width:150px;
}

.combobox input{
z-index:1;
position:absolute;
left:0;
width:100%;
opacity:1;
}

.combobox .select-btn{
position:absolute;
left:0;
width:calc(100% + 20px);
}

</style>

Eric Shulman

unread,
Nov 4, 2021, 4:42:29 PM11/4/21
to TiddlyWiki
On Thursday, November 4, 2021 at 12:31:14 PM UTC-7 Télumire wrote:
Here's the code to push the dropdown in the proper place :

There are layout problems with this solution.  To see the issues,
try putting "before" and "after" text surrounding the "combobox" span:
 
BEFORE<span class="combobox">

<$select field=selection class="select-btn" >
<option value='cities'>A Tale of Two Cities</option>
<option value='science'>A New Kind of Science</option>
<option value='dice'>The Dice Man</option>
</$select>
<$edit-text field=selection placeholder="type or select"/>
</span>AFTER

and compare this with the result of showing only an $edit-text widget:

BEFORE<$edit-text field=selection placeholder="type or select"/>AFTER

For the simple inline $edit-text widget, the BEFORE/AFTER text appears as you would expect:
immediately preceding/following the input element and vertically aligned with the middle of the text

However, note the placement and vertical alignment of the "combobox" elements:
The edit input/select elements appear vertically aligned below the baseline of the surrounding BEFORE/AFTER text,
and the AFTER text is immediately following the input element, rather than following the select element.

The CSS you provided also assumes that the width of the select element's downarrow button will always
a fixed width of "20px", which may not be the case depending upon which browser you are using.

Also, there is also a slight difference in the height of the select element vs the edit element (testing with Chrome),
so that the bottom border of the select element, which is behind the edit element, is visible, creating the appearance
of a double-thick bottom border on the edit element

-e

Mat

unread,
Nov 4, 2021, 5:48:23 PM11/4/21
to TiddlyWiki
@Télumire, I appreciate your effort! @Eric, thank you for your shrewd analysis!

Does anyone know why it is barely possible to manipulate this dropdown though? I do get the following to work, so the options are targettable:

.select-btn option {background:red}

...but attempting to e.g position absolute, margin-left, or some such fails. It is as if they are immune to most styling.

@anyone - is this because of the SelectWidget implementation, or is it the underlying html select / option tags? Surely people will want to style these? If it indeed is the underlying html tags, then is it at all possible to do something about it in the SelectWidget, hypothetically?

Thanx!

<:-)

Télumire

unread,
Nov 4, 2021, 6:17:51 PM11/4/21
to TiddlyWiki

@Eric Shulman my bad, I should have tested it a bit more. Thanks for pointing this out ! @Mat, this is because the select element is OS dependent according to this stack overflow answer : https://stackoverflow.com/a/1895485/11549574

This one can be used properly inline (with a text after and before) and use a pseudo element as a select button (I left it as a red square but it's easy to customize), but there is still an issue with vertical align.. I'm still sharing it just in case, if I find something better I'll post it  :

<$vars

height="20px"


>
<style>
.combobox{
position: relative;
display: inline-block;
width: 150px;
height:<<height>>;
background:red;
margin-right:20px;
}

.combobox .select-btn{
width:100%;
cursor:pointer;
opacity:0;
pointer-event:all;
}

.combobox input{
top:0;
position:absolute;
width:100%;
}

.combobox .drodown-btn{
width:calc(<<height>> + 100%);
top:0;
position:absolute;
cursor:pointer;
}

.combobox .drodown-btn:after{
display:block;
content:"";
width:calc(<<height>> + 4px);
position:absolute;
inset:0 0 0 auto;
background:red;
pointer-events: none;
}
</style>



BEFORE<$edit-text field=selection placeholder="type or select"/>AFTER

before
<span class="combobox">
<span class="drodown-btn">

<$select field=selection class="select-btn" >
<option value='cities'>A Tale of Two Cities</option>
<option value='science'>A New Kind of Science</option>
<option value='dice'>The Dice Man</option>
</$select>
</span>

<$edit-text field=selection placeholder="type or select"/>
</span>
after


Télumire

unread,
Nov 4, 2021, 9:00:46 PM11/4/21
to TiddlyWiki
Combobox.tid

Mat

unread,
Nov 5, 2021, 3:50:56 AM11/5/21
to TiddlyWiki
@Telumire - Man, that turned out quite ambitious. Looks great! Of course, we're way past "I found a way to quickly throw together a combobox", but IF one has the styles, perhaps as part of ones standard custom stylesheets, then it is only a matter applying it with @@.combobox.
For the record, here's the general and simplified call:

@@.combobox
<$edit-text field=selection placeholder="type or select"/>
<$select field=selection>
...options list...
</$select>
@@

@Telumire - I put up a combobox.tiddlyhost.com for the idea. May I include your stylesheet there, obviously with credits to you and a ref to this thread? The purpose with the page is to make it findable when one needs it. (I temporarily just made that page public, it is obviously not ready for anyone to see.)

<:-)

John D

unread,
Nov 5, 2021, 9:56:26 AM11/5/21
to tiddl...@googlegroups.com
Thanks @Mat! Sure, go ahead :)

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/2b0e65a7-7f03-4445-bcec-4dc19eb4933bn%40googlegroups.com.

Mat

unread,
Nov 13, 2021, 6:09:51 PM11/13/21
to TiddlyWiki
@Télumire - I now tried to copy your code but it doesn't work properly. I've tried both from your attached tid file and using the copy-to-clipboard feature on your webpage but the code seems buggy e.g the -- prefix on css variables are enclosed in apostrophes. 

This is what I get, i.e the "Combobox" tiddler is your downloaded attachment tid above, and in the tiddler "A styled combobox" I've tweaked some stuff so it basically works but the button arrow is not showing.

What am I doing wrong or missing?

Thanx

<:-)
On Friday, November 5, 2021 at 2:00:46 AM UTC+1 Télumire wrote:

Télumire

unread,
Nov 13, 2021, 9:27:46 PM11/13/21
to TiddlyWiki
 
Hi @Mat, the apostrophes are intended, they prevent the wikitext parsing to convert the -- into – (the wikitext cant be disabled with a pragma rule or a content type in thatcase because this would prevent the use of widgets).

Drag & drop this tiddler in your wiki and it should work fine (it does on my end in a fresh tiddlywiki) :)
combobox_style.tid

Mat

unread,
Nov 14, 2021, 3:02:10 AM11/14/21
to TiddlyWiki
Thanks Télumire using your exact styling tiddler, but with an added type:text/css  this is how it appears, i.e om my Win 10 machine using Chrome, Brave and Firefox I see a selectwidget but no visible button and you can't type into it. Same thing on my android phone, Brave browser. Does my page not appear like that on your machine? BTW, on your webpage, the combobox tiddler is folded and on my phone I can't access the unfold button.

<:-)

Télumire

unread,
Nov 14, 2021, 3:27:50 PM11/14/21
to TiddlyWiki
With the content type text/css , tiddlywiki treats the content of the tiddler as plain text, and since I rely on wikitext parsing this breaks the stylesheet. You need to use the content type text/vnd.tiddlywiki  or leave the type field blank (since this is the default type for a tiddler).

I uploaded a demo on https://combobox-demo.tiddlyhost.com/, it works both on my laptop (tested with edge, chrome, firefox, brave) and smartphone (chrome and firefox android). If this still doesn't work for you maybe it is because of one of your browser add-ons ?

Another possible explanation is that you have a broken CSS stylesheet somewhere on your wiki, this can break subsequent stylesheets.

I investigated and it doesn't seem to be the case in your demo.
Reply all
Reply to author
Forward
0 new messages