Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tab focus #458

Merged
merged 14 commits into from
May 4, 2022
Merged

Tab focus #458

merged 14 commits into from
May 4, 2022

Conversation

willmcgugan
Copy link
Collaborator

@willmcgugan willmcgugan commented May 3, 2022

  • Tab shows focused widget, tab again moves to next widget, shift+tab moves to previous widget
  • Drops css parameter on App, in favor of CSS class attribute
  • Adds Tint renderable and CSS declaration
  • Fixes issue where universal selector didn't respect pseudo selectors

@willmcgugan willmcgugan changed the base branch from main to css May 3, 2022 16:30
@willmcgugan willmcgugan marked this pull request as draft May 3, 2022 16:31
@@ -91,7 +91,7 @@ class BasicApp(App):

def on_load(self):
"""Bind keys here."""
self.bind("tab", "toggle_class('#sidebar', '-active')")
self.bind("s", "toggle_class('#sidebar', '-active')")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The app now uses tab. Which means we can't use tab elsewhere. Is this a reasonable sacrifice?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only use case of letting be used in the userland space of Textual would be for widgets that let people edit some code? In which case, the equivalent of a browser's textarea could take priority over the behaviour of "pressing tab" - but I reckon this would break accessibility.
I don't know what the best practices are in terms of managing a11y and code editing?

@codecov-commenter
Copy link

codecov-commenter commented May 4, 2022

Codecov Report

Merging #458 (740c4ce) into css (386aa6d) will increase coverage by 15.31%.
The diff coverage is 56.79%.

@@             Coverage Diff             @@
##              css     #458       +/-   ##
===========================================
+ Coverage   38.06%   53.37%   +15.31%     
===========================================
  Files          85      102       +17     
  Lines        6526     8436     +1910     
===========================================
+ Hits         2484     4503     +2019     
+ Misses       4042     3933      -109     
Flag Coverage Δ
unittests 53.37% <56.79%> (+15.31%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/textual/_event_broker.py 50.00% <ø> (+50.00%) ⬆️
src/textual/drivers/win32.py 0.00% <0.00%> (ø)
src/textual/drivers/windows_driver.py 0.00% <0.00%> (ø)
src/textual/layout.py 0.00% <0.00%> (-29.92%) ⬇️
src/textual/renderables/blank.py 0.00% <0.00%> (ø)
src/textual/renderables/gradient.py 0.00% <0.00%> (ø)
src/textual/scrollbar.py 0.00% <0.00%> (ø)
src/textual/views/_dock_view.py 0.00% <0.00%> (ø)
src/textual/views/_document_view.py 0.00% <0.00%> (ø)
src/textual/views/_grid_view.py 0.00% <0.00%> (ø)
... and 100 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e5a1543...740c4ce. Read the comment docs.

@willmcgugan willmcgugan marked this pull request as ready for review May 4, 2022 10:28
Copy link

@olivierphi olivierphi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
I only have superficial comments that you're totally free to ignore :-)

@@ -91,7 +91,7 @@ class BasicApp(App):

def on_load(self):
"""Bind keys here."""
self.bind("tab", "toggle_class('#sidebar', '-active')")
self.bind("s", "toggle_class('#sidebar', '-active')")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only use case of letting be used in the userland space of Textual would be for widgets that let people edit some code? In which case, the equivalent of a browser's textarea could take priority over the behaviour of "pressing tab" - but I reckon this would break accessibility.
I don't know what the best practices are in terms of managing a11y and code editing?

src/textual/app.py Outdated Show resolved Hide resolved
src/textual/app.py Outdated Show resolved Hide resolved
@@ -87,7 +98,9 @@ class ActionError(Exception):
class App(Generic[ReturnType], DOMNode):
"""The base class for Textual Applications"""

css = ""
CSS = """

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure I understand correctly... The only reason we can move this to a class-level variable that can no longer be overridden in the constructor is because we expect to never have more than one instance of App instantiated in a Python program, right? 🙂
(so customising this CSS at the class level can only be be done before instantiating an App for the first time)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can still define a subclass with different CSS.

I wanted to remove it from the constructor so that there is only one place to included the CSS if its a string literal. A classvar constant seems like the best place.

@@ -233,7 +240,7 @@ async def _process_messages(self) -> None:
except CancelledError:
raise
except Exception as error:
self.app.panic(error)
self.app.on_exception(error)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darrenburns pretty sure this is the cause of the "can't render blah..." error you saw.

src/textual/app.py Outdated Show resolved Hide resolved
@darrenburns
Copy link
Member

Only other thing I want to mention here is that we might need to revisit the accessibility of this (either by default or via config) since it's just overlaying a colour. We may need an option to display some kind of marker too.

@willmcgugan
Copy link
Collaborator Author

Yeah, we need something other than commit to show focus. Underline in addition to colour makes sense, but we have that issue that it underlines everything.

@willmcgugan willmcgugan merged commit 7ae4c73 into css May 4, 2022
@willmcgugan willmcgugan deleted the tab-focus branch May 4, 2022 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants