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

Improve class selectors for navigation #2852

Merged
merged 8 commits into from Feb 28, 2020

Conversation

bartaz
Copy link
Contributor

@bartaz bartaz commented Feb 26, 2020

Done

  • introduces new navigation class names (p-navigation__items, p-navigation__item, p-navigation__link) to be used in place of existing p-navigation__links, p-navigation__link and classless <a>
  • deprecates the use of old classes and selectors
  • updates the documentation and examples

Fixes #2168
Fixes #1746

QA

  • Pull code and ./run
  • Open http://0.0.0.0:8101/ or demo
  • Check all navigation examples
  • They should work as expected with new classes
  • New "deprecated" examples should also work with old classes
  • Check component status - make sure changes to navigation are listed
  • Check navigation documentation - make sure deprecated classes are documented

Please note - embedded CodePen examples will not work because they use published version of Vanilla, not latest one in development.

@webteam-app
Copy link

@anthonydillon
Copy link
Contributor

@bartaz out of curiosity. What is the benefit of moving the styles into one use placeholders? I tend to try and put the code where a developer would look first for something.

@bartaz
Copy link
Contributor Author

bartaz commented Feb 26, 2020

@anthonydillon These parts will be duplicated for new class names and current deprecated ones.

Not to duplicate the code, I moved it to placeholders so both new and old class names can extend from it. Old ones will be wrapped in deprecate.

@bartaz bartaz changed the title WIP: Move some of navigation styles to placeholders WIP: Improve class selectors for navigation Feb 26, 2020
@anthonydillon
Copy link
Contributor

Makes sense 👍 forgot about the wrapping deprecate mixin. Thanks for explaining.

@bartaz bartaz changed the title WIP: Improve class selectors for navigation Improve class selectors for navigation Feb 27, 2020
@bartaz bartaz marked this pull request as ready for review February 27, 2020 10:15
@lyubomir-popov
Copy link
Contributor

@bartaz would it be scope creep to fix the p-subnav situation? Shouldn't subnav just be a modifier instead of a separate pattern that is however tied theme-wise to the nav, which causes some unnecessary complications.

@bartaz
Copy link
Contributor Author

bartaz commented Feb 27, 2020

@lyubomir-popov I agree that we should fix subnav, but this PR got quite complex even without it.

I created #2857 so we have this in backlog.

Copy link
Contributor

@anthonydillon anthonydillon left a comment

Choose a reason for hiding this comment

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

Few questions in the code.

docs/examples/patterns/navigation/_script.js Outdated Show resolved Hide resolved
docs/examples/patterns/navigation/_script.js Outdated Show resolved Hide resolved
Closes all subnavs on the page.
*/
function closeAllSubnavs() {
var subnavs = document.querySelectorAll('.p-subnav');
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if its ever likely to have more then one on a page at a time? In that case we could limit the search to the used subnav.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Why wouldn't you have multiple dropdowns in the navigation? We have this in our example where each item in menu is a dropdown.

event.preventDefault();
event.stopPropagation();

var subnav = subnavToggle.parentElement;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use closest so the JS doesnt need to change if the markup does

Copy link
Contributor Author

Choose a reason for hiding this comment

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

closest is not supported by IE. We would need to polyfill that.


In Vanilla 2.8 we deprecated the use of `p-navigation__links`, `p-navigation__link` and classless `<a>` in the navigation. Support for these classes will be removed in future version 3.0.

You should use `p-navigation__items`, `p-navigation__item` and `<a class="p-navigation__link">` instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should start a 3.0 upgrade document now so its easier when it comes to it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created issue about it #2858

@extend %navigation-link-dark;
}

.p-navigation__item.is-selected > .p-navigation__link {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the sibling selector now that we are directly targeting classes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. In this case it depends on is-selected state of the parent. I guess we could simplify it to .p-navigation__item.is-selected .p-navigation__link if that's what you mean.

padding-right: 2 * $sph-inner--small + map-get($icon-sizes, default); // icon padded with the default padding-right of selects, inputs etc.
}

.p-subnav > .p-navigation__link {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems strange to cross use two patterns here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's been like this before. I don't want to change it in this PR. I opened a separate issue to move p-subnav into navigation #2857.

Copy link
Contributor

@anthonydillon anthonydillon left a comment

Choose a reason for hiding this comment

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

Thanks for the replies.

@anthonydillon
Copy link
Contributor

Not really a breaking change 🏅

@anthonydillon anthonydillon merged commit cbb183d into canonical:master Feb 28, 2020
@bartaz
Copy link
Contributor Author

bartaz commented Feb 28, 2020

Not really a breaking change 🏅

@anthonydillon Yes, when we deprecate things there are never really breaking changes (at least not intentionally). I use this label to remind myself to mention the deprecated classes in release notes.

@bartaz bartaz deleted the navigation-cleanup branch February 28, 2020 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

p-navigation relies on element selectors Deeply nested selectors of navigation pattern
4 participants