Could someone let me know how can I automatically scroll the scrollView when a keyboard-only user tries to navigate between different UI Element in the ScrollView using ‘Tab’ key? When I hit "TAB" key the focus is shifted to different UI element present in the scrollView but it doesn't scroll if the UI Element is not present in the Visible Content View. How can this be achieved. Help would be appreciated. Thanks.
By default a tab press does several things: If the screen for the tab renders a scroll view, you can use useScrollToTop to scroll it to top If the screen for the tab renders a stack navigator, a popToTop action is performed on the stack To prevent the default behavior, you can call event.preventDefault:
Tab Scrolling is not a feature that Microsoft added to the browser; instead, it is a feature that is added to the Chromium core. You can enable it in Google Chrome development versions right now, but when you check the flags page in Edge, you will notice that the flag is missing.
Yet, in order to be able to scroll back up, I wrap all the page content (including the navigator) in a ScrollView. When using v2, the TabNavigator would expand to its content size, thus making it visible without having to implement a scrollview in the screens of the navigator.
By default, tabs get smaller and smaller the more you open, but there is no option to scroll them. Microsoft did introduce support for vertical tabs in the recent release of Edge 89 Stable, and the feature is suggested to users when too many tabs are opened.
Solution A: Create a subclass of NSWindow
and override makeFirstResponder:
. makeFirstResponder
is called when the first responder changes.
- (BOOL)makeFirstResponder:(NSResponder *)responder {
BOOL madeFirstResponder = [super makeFirstResponder:responder];
if (madeFirstResponder) {
id view = [self firstResponder];
// check if the new first responder is a field editor
if (view && [view isKindOfClass:[NSTextView class]] && [view isFieldEditor])
view = [view delegate]; // the control, usually a NSTextField
if (view && [view isKindOfClass:[NSControl class]] && [view enclosingScrollView]) {
NSRect rect = [view bounds];
rect = NSInsetRect(rect, -10.0, -10.0); // add a margin
[view scrollRectToVisible:rect];
}
}
return madeFirstResponder;
}
Solution B: Create a subclass of NSTextField
and other controls and override becomeFirstResponder
.
- (BOOL)becomeFirstResponder {
BOOL becameFirstResponder = [super becomeFirstResponder];
if (becameFirstResponder) {
if ([self enclosingScrollView]) {
NSRect rect = [self bounds];
rect = NSInsetRect(rect, -10.0, -10.0); // add a margin
[self scrollRectToVisible:rect];
}
}
return becameFirstResponder;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With