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

Move default scroll navigation keys out of Widget and into ScrollableContainer #2337

Merged
merged 11 commits into from
Apr 20, 2023

Conversation

davep
Copy link
Contributor

@davep davep commented Apr 20, 2023

This PR removes the default bindings for navigation keys -- binding them to various scroll actions -- from Widget and introduces them in a new ScrollableContainer container. Primarily this is to address #2100; the problem here being that not all widgets want to scroll, but many non-scrolling widgets will want to do other things with navigation keys and the bindings can end up clashing when it comes to sorting out descriptions and entries (or lack of them) in the Footer of an application.

This is a breaking change. Any widget that scrolls, and expects keyboard-driven scrolling "out of the box", will cease to be navigable via the keyboard. This is easily solved by switching to ScrollableContainer, VerticalScroll or HorizontalScroll as the parent (so far any examples I've seen where this is an issue have inherited from Widget or Container so changing the parent class won't be much of a change).

This PR also goes on to change the demo, plus ScrollView, to ensure scrolling works as before there.

I've run through the main examples and they all look fine.

While the main thrust of this PR sort of renders the need to do it moot, I've also rolled #2331 in here too; mostly now this will work as a guard against any default bindings that may get added to Widget in the future, such that we should think about the consequences for containers.

The idea here is that not every widget will scroll, and as such not every
widget needs to have default bindings for calling the scrolling methods.
Generally scrolling is something done in a container.

These days we have *Scroll containers. As such it makes sense to introduce
the bindings in a common parent class for those containers.

This commit moves the binding from widget and creates that common parent
class, and then has HorizontalScroll and VerticalScroll inherit from it.

This is, it should be noted, a breaking change. Any code that creates a
scrolling widget that assumes that the bindings are just there, where that
widget doesn't inherit either from HorizontalScroll or VerticalScroll, will
suddenly find that scrolling with the keyboard is no longer possible.

See Textualize#2332.
The `Body` class inherited from `Container` rather than one of the scrolling
containers; until now it had worked because `Widget` provided the bindings
to make this happen, now that they've moved into `ScrollableContainer` that
stopped working.
This is, to some degree, rendered moot by Textualize#2332, but for the moment it still
feels worth doing. The initial intention was to make sure that non-scrolling
containers and their child classes don't have bindings that may mask other
uses for navigation keys. However, it was realised that the "problem"
affected more than just containers (hence Textualize#2332).

But... on the off chance we add any more default bindings to
`Widget` (unlikely, but still), this will mean that they don't leak into the
containers unless we intend them to.

See Textualize#2331.
…oach

Now that navigation bindings don't pollute the whole widget hierarchy any
more some of these tests can be tidied up.
I'd accidentally started adding things under v0.20.1 rather than under a new
unreleased heading.
Copy link
Contributor

@rodrigogiraoserrao rodrigogiraoserrao left a comment

Choose a reason for hiding this comment

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

Nice! 🚀

For what is worth, to me it makes a LOT of sense to have a base class for scrollable containers, irregardless of the fuss I made yesterday about bindings and show=False and etc.

CHANGELOG.md Outdated Show resolved Hide resolved
src/textual/scroll_view.py Outdated Show resolved Hide resolved
davep and others added 3 commits April 20, 2023 11:13
Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
@davep davep merged commit d4f7ef0 into Textualize:main Apr 20, 2023
@davep davep deleted the bug/2100/invisible-keys branch April 20, 2023 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request Task
Projects
None yet
3 participants