-
Notifications
You must be signed in to change notification settings - Fork 153
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
[Main nav] Navigation column [TP-266] #12047
[Main nav] Navigation column [TP-266] #12047
Conversation
class NavColumn(blocks.StructBlock): | ||
title = blocks.CharBlock(max_length=100) | ||
links = blocks.ListBlock(NavItem, min_num=1, max_num=4) | ||
button = blocks.ListBlock(NavButton, required=False, min_num=0, max_num=1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @jhonatan-lopes, is this dev pattern of encompassing a block w/ max_num=1 in a ListBlock useful for:
- Cleaner UI by hiding fields if child block not used
- Additional control by not requiring the child block itself (and then requiring the child block fields if it's been added)
- Anything else I'm missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @robdivincenzo, this is documented here: https://docs.wagtail.org/en/stable/topics/streamfield.html#limiting-block-counts
Basically, we can use min_num
and max_num
to limit the number of blocks in a ListBlock
or StreamBlock
combination. In this case, we need at least one link and at most 4. Button, on the other hand, is optional, so we use the ListBlock
with min_num=0
and max_num=1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM @jhonatan-lopes, great work! One comment, but not a change request
a96ddfa
into
feature-branch/main-nav-dropdown
* Add description to NavLinkBlock * Rename NavLinkBlock to NavItem * Add NavButtonBlock * Fix test name * Add a NavColumn model
* Add description to NavLinkBlock * Rename NavLinkBlock to NavItem * Add NavButtonBlock * Fix test name * Add a NavColumn model
* Add description to NavLinkBlock * Rename NavLinkBlock to NavItem * Add NavButtonBlock * Fix test name * Add a NavColumn model
* Add description to NavLinkBlock * Rename NavLinkBlock to NavItem * Add NavButtonBlock * Fix test name * Add a NavColumn model
* Add description to NavLinkBlock * Rename NavLinkBlock to NavItem * Add NavButtonBlock * Fix test name * Add a NavColumn model
Description
Implement a
NavColumn
andNavButton
blocks.Link to sample test page:
Related PRs/issues:
Checklist
Tests
Changes in Models:
[ ] Did I squash my migration?[ ] Are my changes backward-compatible. If not, did I schedule a deploy with the rest of the team?Documentation:
[ ] Did I update the READMEs or wagtail documentation?Merge Method
💡❗Remember to use squash merge when merging non-feature branches into
main
┆Issue is synchronized with this Jira Story