[Ur] Grabbing focus

Edward Z. Yang ezyang at MIT.EDU
Sat May 19 00:24:56 EDT 2012


I realized that this generalizes a little.  Consider the <body onload>
attribute: this is some client-side code that runs when the page
finishes rendering.  Let's suppose that I want to divide up an Ur/Web
page into multiple sections, each of which has their own onload fragment.
There is no way to do this currently (onload is not compositional).
But you end up in the same place as figuring out when something should
"grab focus" (in this regime, I need a way of getting a source associated
with focusing, and then I have some code in the onload which triggers
the source.)

I want this ability for something else: I'm building a widget which
should be able to be incorporated into a page multiple times, but
which must be rendered client-side because it uses higher-order
functions (so we currently instantiate it from onload).

Edward

Excerpts from Edward Z. Yang's message of Thu May 17 14:23:13 -0400 2012:
> Excerpts from Adam Chlipala's message of Thu May 17 08:50:51 -0400 2012:
> > What about a pseudo-attribute (of type [bool] or [unit]) for focus-able 
> > elements, asking to give them focus upon creation?  Maybe this is your 
> > first suggestion above.
> 
> Unfortunately, it's not clear if "on creation" is well defined or
> has the desired semantics.  If I generate an XML fragment but don't
> put it on the page, it shouldn't grab focus.
> 
> > What would be a usual way of implementing this in HTML/JavaScript?
> 
> Let 'el' be a DOMElement that is focusable, then you can focus it
> by doing 'el.focus()'.
> 
> Cheers,
> Edward



More information about the Ur mailing list