It is best to laugh when you encounter these little glitches, note them, and then quickly not brood over exactly how dumb someone had to be to miss X.
This article deals w/ Tab order and some of the issues you'll encounter
So Tab order is pretty straightforward in virtually every environment. For the novice, this is when you hit Tab or Alt-Tab while moving through a series of fields/controls. It is just basic plumbing that just works w/o consideration. Except here.
For the most part, your assumptions are correct. The values of TabIndex on a control apply as follows:
- -1 : Never visit this control
- 0 : Default
- 1,2,3,10...100 : Ascending order of movement
Defaults and Concerns
From my experience, in all cases all fields default to Zero (0). However, the treatment of "which Zero" comes next can be strange at best. In particular, if you have created an Edit Form and linked it to a data source. One of the first things you'll do is start moving fields around on the page and that's when Tab order gets...wonky.
You might believe that PowerApps set your TabIndex field for you (supposedly the ultimate arbiter of Tab order). It didn't. It just kinda did some magic behind the scenes of how it thought you wanted things and then hid all of that logic from you. Which, IMHO, is far worse that just defaulting the order. Particularly in that it sometimes causes the first issue I note in the Troubleshooting section below.
In practice, fields with identical values of TabIndex should probably move left->right, top->bottom along the screen for identical TabIndex values. And perhaps, that is how the application works...initially. However, when you start moving fields around then the order can become completely screwed up even when you're sitting there staring at TabIndex values that are clearly correct (e.g. you renamed them to 1,2,3...).
NOTE: During a retest in 2023, it appears Microsoft is setting the TabIndex on certain "unlikely for you to expect to tab to" controls to -1 by default, but any normal control is still set to 0.
Rules
Best Practices
No Zeroes
Standardize on high-value TabIndex for common controls
Change the TabIndex along with the Visible property
- If(Parent.visible,1,-1) (or alternatively)
- If(Self.visible, 1, -1)
Is this necessary? I have no idea, but some very strange things are going on w/ Tab order and this definitely seems to smooth things out.
Troubleshooting
When in doubt, delete the control.
"Something" strange has happened. I've had it happen a few times. The only 100% successful answer I have is to delete the control and recreate. I've solved this a number of times w/ icons or fields that simply wouldn't work properly. You could create an identically functioning control and copy all values and one works but the other doesn't. I don't know what to tell you other than to not waste time on something like this. It is just a part of the current environment.
If you have a control that isn't showing focus (e.g. no change in border or color) then the most likely issue is that it isn't getting focus. The issue is not that you have some wonky value on your "OnFocus" color schema. The control is screwed up. Delete and recreate first before you waste more time.
Don't fuss over TabIndex early
The <Enter> key "doesn't work"
Ok, this isn't 100% true. If you have a normally responsive control selected (e.g. a button) and hit the <Enter> key (or the spacebar), then the control's "OnSelect" event fires. Same for icons. HOWEVER, for fields (e.g. edit form field), the OnSelect event fires if the control is clicked into (e.g. mouse). IT DOES NOT FIRE WHEN YOU HIT <ENTER>.
This and other "quirks" of PowerApps are primarily due to the #1 focus for PowerApps being mobile. Since there is not generally an <Enter> key style behavior on mobile (users are expected to touch a button/control), that was overlooked and/or de-prioritized since it primarily impacts desktop users.
Containers can throw things off (2023/2/1)
The new Container controls seem to take a Tab space themselves even if they have no actual TabIndex property. So be aware that if you use containers, then one of the Tab presses will enter/exit the container and THEN go to the next control in your list.
So if I have an item w/ a TabIndex of 1 in one Container and another w/ 2 in another Container, then there will be 2 Tab presses to get there. First to go to the next Container, next to go to the next control inside the Container.
It almost makes sense, but...no.
I'm having an odd issue (what issue with Power Apps isn't odd, right?) with tab order on a screen that seems to fall outside of your Troubleshooting. I've posted it in the Power Users forums (https://powerusers.microsoft.com/t5/Building-Power-Apps/TabIndex-issue/m-p/441309/highlight/false#M130861), so I won't reiterate the details here, but if you have any insight and could reply over there or to me via email, I would really appreciate the help!
ReplyDeleteNot that I'd call this a long-term solution, but you could change the Tab Order on your problem control to a variable. Start the variable as a -1 and then when you access any of the other controls you change the variable to be what it is supposed to be.
DeleteI can take a look and see if I can recreate but that might be a quick punt to get around the issue temporarily.
Thanks for sharing, John. This was a funny blogpost.
ReplyDeleteThanks for the tips and the laugh. I just realized the HTML text field does not have the option for a tab order.... joy.
ReplyDelete