medialize / ally.js

JavaScript library to help modern web applications with accessibility concerns

Home Page:http://allyjs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Making it possible to distinguish touch/mouse as source of focus

darobin opened this issue · comments

Right now data-focus-source makes it possible to tell keyboard from pointer as the source of focus. We (@halmos and I) would like to be able to further distinguish different types of pointers. The use case is to be able to provide a thicker (or otherwise more visible) focus outline on touch, because you can't see what's under your finger.

In terms of how this gets exposed, I don't think we can change data-focus-source without breaking compatibility. So that would always reflect "pointer". But we can add a second data attribute, say data-pointer-type, that could contain touch/mouse/stylus/catpaw/headbang/etc.

In terms of implementation, just giving it a quick look I believe that https://github.com/medialize/ally.js/blob/master/src/observe/interaction-type.js could expose that distinction (since it knows what event it's reacting to) by incrementing/decrementing modality-specific counters in addition to the pointer one, and then that https://github.com/medialize/ally.js/blob/master/src/style/focus-source.js#L52 could simply make use of that information.

We're open to other approaches of course, this is just what we've thought up. If you're up for this, we'd be happy to file a PR.

I like your approach! Much simpler than what I had in mind.

I think I'd call the attribute data-focus-source-pointer="<value>". And <value> would returned by observe/interaction-type as a third property called pointerType, with its value defined by event.pointerType. I assume there's no mix'n'match, so modality-specific counters don't seem necessary. <value> would default to null, be "touch" for event.type === "touchstart", "mouse" for event.type === "mousedown" and otherwise whatever event.pointerType returns.

of course I'd love a PR for this :)

how is this going looking into this?

I'm not aware anyone has put work into this yet. Are you up for it?