Re: Fw: [devel-frontend] [Fwd: Getting the tabindex value with JavaScript on elements without a tabindex attribute]

On Dec 16, 2007 1:29 PM, Tomomi Imura <tomomi@yahoo-inc.com> wrote:
>
>
>
> --- On Fri, 12/14/07, Victor Tsaran <vtsaran@yahoo-inc.com> wrote:
>
> > From: Victor Tsaran <vtsaran@yahoo-inc.com>
> > Subject: [devel-frontend] [Fwd: Getting the tabindex value with JavaScript on elements without a  tabindex attribute]
> > To: devel-frontend@yahoo-inc.com
> > Date: Friday, December 14, 2007, 2:06 PM
> > Hmmm, interesting...
> >
> > Victor
> >
> >
> >
> >
> >
> > -------- Original Message --------
> >
> >
> >
> >       Subject:
> >       Getting the tabindex value with JavaScript on
> > elements
> > without a tabindex attribute
> >
> >
> >       Resent-Date:
> >       Fri, 14 Dec 2007 21:58:02  0000
> >
> >
> >       Resent-From:
> >       wai-xtech@w3.org
> >
> >
> >       Date:
> >       Fri, 14 Dec 2007 16:55:25 -0500
> >
> >
> >       From:
> >       Simon Bates <simon.bates@utoronto.ca>
> >
> >
> >       To:
> >       wai-xtech@w3.org
> >
> >
> >       CC:
> >       fluid-work@fluidproject.org
> > <fluid-work@fluidproject.org>
> >
> >
> >
> >
> >
> > On IE it is not possible to determine whether a div has no
> > tabindex or
> > tabindex="0" using
> > elem.getAttribute("tabindex") or elem.tabIndex
> > because a default value of 0 is returned.

IE reflects the tabIndex property in getAttribute( 'tabIndex' ).

http://developer.mozilla.org/en/docs/DOM:element.getAttribute

document.body.style.color = "red";
typeof document.body.getAttribute("style"); // should be "string"
(though not req'd, DOMString should convert to string)
typeof document.body.style; // should be "object" (though not req'd,
host objects usually convert to object)

> > provides an
> > extension to getAttribute() that can be used to determine
> > if the
> > tabindex is unset. If a second parameter of value
> > "2" is passed to
> > getAttribute(), a value of 32768 is returned whenever
> > tabindex is not
> > set. See Microsoft's documentation on getAttribute:
> >
> > http://msdn2.microsoft.com/en-us/library/ms536429.aspx
> >
> > I have been unable to find documentation on the value of
> > 32768 as used
> > for tabIndex but it is outside of the range of 0 to 32767

Character MAX_VALUE;

It's a useless value here. It's a bug of IE; I'm not sure how they
ended up with that value. Maybe someone else could guess better.

32767 in binary: 1000 0000 0000 0000

32768 .toString(2);

You're testpage has a 'specified' check. That seems safer.

if( isTabIndexSpecified( el ) ) {

}
else {

}

function isTabIndexSpecified( el ) {
  return Boolean(el.attributes.tabIndex && el.attributes.tabIndex.specified);
}

Another approach is to just let the developer/API user take care of
a11y. This could be a param or method setDefaultKbdAccess:

function setDefaultKbdAccess(el){
// For IE, if the attribute is not present, 0 will be returned.
	// For Moz, Webkit, Op, if attribute is not present, null will be returned,
	// but the default value for the DOM property will be -1 (truthy), so
use getAttribute.
	if(!el.getAttribute('tabIndex')) el.tabIndex = 0; // Allow default
kbd navigation.
}

Dojo should not be needed for this.

HTML 5 defines attributes reflecting of attributes a little better.

Regards,

Garrett

> > specified by
> > HTML 4:
> >
> > http://www.w3.org/TR/html401/interact/forms.html#adef-tabindex
> >
> > Safari 3.0.4 Mac
> >
> > div with no tabindex:
> >       elem.getAttribute("tabindex") = null
> >       elem.tabIndex = undefined
> >
> > input with no tabindex:
> >       elem.getAttribute("tabindex") = null
> >       elem.tabIndex = 0
> >
> > Test file used to gather results:
> >
> > http://trac.bitstructures.com/browser/collected/trunk/html-test-cases/getting-tabindex.html?format=raw
> >
> > Collected test results:
> >
> > http://trac.bitstructures.com/browser/collected/trunk/html-test-cases/getting-tabindex-results.html?format=raw
> >
> > Please let me know if you see any shortcomings in the test
> > file or results.
> >
> > Simon Bates
> > Adaptive Technology Resource Centre
> > University of Toronto
>
>



-- 
Monkey, so they say, is the root of all people today.

Received on Sunday, 16 December 2007 23:17:10 UTC