I have a button that, when it has focus, has a special style.
I have a form with only a series of these fancy buttons; when it loads, the first button in the series is displaying the special style to indicate it has focus. It's functionally fine, but visually annoying.
I have resolved this with:
<TextBox width="1" Height="1" />
But this feels like a kludge.
Is there a better way to prevent anything from having the initial focus?
By default, focus should be on window and not on button. Are you unknowingly, setting focus on button either using focus method or tab index?
Related
I'm using ReactJS and I have a lot of <button> in my code. I notice that I can use the Tab key to move over the button and there will be an outline on focused button like this:
But on this website which I'm trying to replicate, the buttons they use do not get Tab-focused on normal but just when we turn on the VoiceOver accessibility mode.
And the border of the Tab focus is also different.
I wonder how can we implement this in React?
Changing tabIndex to 0 or -1 doesn't work.
Thanks everyone!
Update
I ask because this leads to a problem:
If I use the UI Keyboard (UIKB) first and then try to type with the real keyboard keydown event. The tab focus would just stuck on the UIKB letter and return it twice.
This doesn't happen on the Wordle game because they just allow using tab focus when in accessibility mode.
tabIndex = -1 doesn't work because I want to allow the user use the tab focus just in a11y mode like Wordle, I don't want to totally disable it.
In My WinRt apps,I need to tap twice on tab button for switch focus from one textbox to another. but i want to switch focus from one textbox to another in single tap on tab button. Please give me correct solution
This works on my app :
myTextBox.Focus(FocusState.Keyboard);
myTextBox.Focus(FocusState.Pointer);
myTextBox.Focus(FocusState.Programmatic);
Most of the time, there is nothing to do to get the tab working.
If you need to press the TAB key twice, you are probably giving the focus to a control you do not expect because the tab order is not what you expect.
You can force the focus order by specifying the TabIndex property on your controls. In this way, you are sure about what will happen when pressing TAB.
<StackPanel>
<TextBox TabIndex="1" />
<TextBox TabIndex="2" />
<TextBox TabIndex="3" />
</StackPanel>
I have some buttons in a bottom toolbar of a gridpanel that control adding, and removing records from the row-editing grid.
The handlers are pretty simple: "new" button creates an instance of the model, appends to the grid and then opens a row-editor on the new row; "edit" button just opens the selected row's row-editor; "remove" destroys the record from the store and refreshes the grid view.
For some reason these buttons don't lose the focus class that gives them a border when they have the focus. Here is a picture:
In the picture both the "New" button and the "Remove" button have the focus class, when I press the "Edit" button it also keeps the focus classes even after doing a complete row-edit operation and closing the row-editor.
I did find that when I mousedown on one of these permanently "focused" buttons and then mouseup away from it and then click something else the focus class goes away.
I know that I could put a blur handler for all button components in my respective controllers but I would have thought that this functionality was built in so I am asking to see if there is something I missed somewhere in the docs.
The classes that it won't let go of are these:
x-focus x-btn-focus x-btn-default-toolbar-small-focus
This is with ExtJS 4.1.0 in FF10 on Windows 7. But I did notice similar behavior in ExtJS 4.02 and 4.07, just haven't needed to handle it until now.
I found out what it was:
At some point in the handler chain for each of these buttons the button gets disabled. When a button is disabled in ExtJS it prevents the blur event from firing.
It was necessary to disable the buttons so the solution to simply add button.blur() in the handler was the correct way to do go about it.
I've got a Tree with custom TreeViewItems. The TreeViewItems contains a CheckBox. When I click on a CheckBox the background logic decides whether the click was valid or not and if it was invalid a warning message should be shown.
I added a Tooltip to each TreeViewItem and set the visibility to Collapsed when doing declaration. The Tooltip should show the message but if I set it to Visible in the TvItems click event it doesn't appears immediately just after it gets the mouseOver event again. Its the same if I set the IsOpen property in the event.
How can I force the Tooltip to appear when I want in this case?
You can try to use the ToolTipService class to set the InitialShowDelay to 0. But i think this will also show the tooltip directly when you hover your mouse over the element.
Maybe you should reconsider this design, because i think what you want to do proves to be difficult in some circumstances or not usable.
If you want to do it on a mouse Click, i would use a attached behavior to hook the mouse click, and show the tooltip by hand, which can be accomplished by grabbing the ToolTip of your TreeViewItem and setting IsOpen to true.
I'm working on a custom button where the content is sometimes a textbox. I'm doing this so I have a sort of edit-in-place where you can type text, hit enter, and then the textbox disappears and the button's text is what was typed.
So as a simple case, you could mock this up like so:
<Button>
<TextBox />
</Button>
The problem is if you hit the <space> or <enter> while typing it'll "click" the button instead of input those keystrokes into the textbox.
Now, like I said, this is a custom button so I can do whatever I need to in the codebehind to get this working.
Just because a TextBox appears over a Button does not mean it should be inside the button :)
You are better off with a custom control that has a button with optional Textbox over it. That way the TextBox will not interfere with the button beahaviour. If you put them both in a grid you will still retain a lot of dynamic layout control.
You will just need to expose properties and events of the button (and probably of the TextBox) on your user control.
If you need specific help, just ask.