pyjamas.ui oddity: Label -> HTML

9 views
Skip to first unread message

Stephen Waterbury

unread,
Mar 7, 2014, 1:46:01 PM3/7/14
to pyjs-...@googlegroups.com
I was recently astonished to discover that the Label widget gets
a 'div' element, not a 'label' element. This bit me while doing
accessibility testing for my app -- screen readers expect all
form fields, inputs etc. to have labels. I was using Label
widgets for that, so I was puzzled when accessibility tools like
the Firefox "WAVE" plugin did not find the labels ... then I
noticed that the Label widgets all had <div> elements, not
<label> elements -- arg.

So my next move was to hack the Label.py code, changing its
DOM.createDiv() to DOM.createLabel(). That fixed the labels but
caused a whole slew of other messages ... hmm, turns out that the
HTML widget inherits from the Label widget ... wtf?? I guess
there must be some weird, counter-intuitive historical reasons
(maybe GWT does that?). So not wanting to do *too* much hacking,
I replaced all my app's HTML widgets with HTMLPanel widgets
(which do *not* inherit from Label), which makes them heavier
than they need to be (they don't really need to be Panels).

If anyone cares and understands what the consequences would be
(e.g. other breakage), I'd suggest switching the positions of
Label and HTML in the pyjamas.ui widget tree -- shouldn't Label
be *more* specific than HTML? (And let HTML inherit from
MouseHandler and ClickHandler, as Label currently does.)

Steve

Stephen Waterbury

unread,
Mar 7, 2014, 2:12:28 PM3/7/14
to pyjs-...@googlegroups.com
So, to answer my own message, I realized that the simplest and
least breakage-inducing solution is for me to create a FormLabel
that inherits from Label and get a label element by way of the
'Element' kwarg (which Label() looks for).

Apologies for the noise ... we now return you to the usual
crickets. ;)

Steve

Glyph Lefkowitz

unread,
Mar 7, 2014, 4:50:51 PM3/7/14
to pyjs-...@googlegroups.com

On Mar 7, 2014, at 11:12 AM, Stephen Waterbury <wate...@pangalactic.us> wrote:

> So, to answer my own message, I realized that the simplest and
> least breakage-inducing solution is for me to create a FormLabel
> that inherits from Label and get a label element by way of the
> 'Element' kwarg (which Label() looks for).

Can you put this into a pull request, so others don't hit it in the future? :)

-glyph

Stephen Waterbury

unread,
Mar 7, 2014, 5:23:02 PM3/7/14
to pyjs-...@googlegroups.com
Good suggestion, Glyph. In the meantime, if anyone is interested
I'd be happy to share the code, off list.

Steve

Reply all
Reply to author
Forward
0 new messages