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

refactor: minor code style improvements and cleanup #5834

Merged
merged 2 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/side-nav/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@

END OF TERMS AND CONDITIONS

Copyright 2017 Vaadin Ltd.
Copyright 2023 Vaadin Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion packages/side-nav/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import '@vaadin/side-nav';

## Themes

Vaadin components come with two built-in [themes](https://vaadin.com/docs/latest/styling), Lumo and Material.
Vaadin components come with two built-in [themes](https://vaadin.com/docs/latest/styling), Lumo and Material.
This component currently does not support Material theme.
The [main entrypoint](https://github.com/vaadin/web-components/blob/main/packages/side-nav/vaadin-side-nav.js) of the package uses the Lumo theme.

Expand Down
4 changes: 2 additions & 2 deletions packages/side-nav/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
"module": "vaadin-side-nav.js",
"type": "module",
"files": [
"enable.js",
"src",
"theme",
"vaadin-*.d.ts",
"vaadin-*.js",
"web-types.json",
"web-types.lit.json",
"enable.js"
"web-types.lit.json"
],
"keywords": [
"Vaadin",
Expand Down
2 changes: 1 addition & 1 deletion packages/side-nav/src/vaadin-side-nav-item.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export type SideNavItemEventMap = HTMLElementEventMap & SideNavItemCustomEventMa
* `prefix` | A slot for content before the label (e.g. an icon).
* `suffix` | A slot for content after the label (e.g. an icon).
*
* #### Example:
* #### Example
*
* ```html
* <vaadin-side-nav-item>
Expand Down
36 changes: 25 additions & 11 deletions packages/side-nav/src/vaadin-side-nav-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function isEnabled() {
* `prefix` | A slot for content before the label (e.g. an icon).
* `suffix` | A slot for content after the label (e.g. an icon).
*
* #### Example:
* #### Example
*
* ```html
* <vaadin-side-nav-item>
Expand All @@ -61,10 +61,6 @@ class SideNavItem extends ElementMixin(ThemableMixin(PolylitMixin(LitElement)))
return 'vaadin-side-nav-item';
}

static get observers() {
return ['__pathChanged(path)'];
}

static get properties() {
return {
/**
Expand Down Expand Up @@ -109,10 +105,33 @@ class SideNavItem extends ElementMixin(ThemableMixin(PolylitMixin(LitElement)))
return this.shadowRoot.querySelector('button');
}

/**
* @protected
* @override
*/
firstUpdated() {
// By default, if the user hasn't provided a custom role,
// the role attribute is set to "listitem".
if (!this.hasAttribute('role')) {
this.setAttribute('role', 'listitem');
}
}

/**
* @protected
* @override
*/
updated(props) {
super.updated(props);

if (props.has('path')) {
this.__updateActive();
}
}

/** @protected */
connectedCallback() {
super.connectedCallback();
this.setAttribute('role', 'listitem');
this.__updateActive();
this.__boundUpdateActive = this.__updateActive.bind(this);
window.addEventListener('popstate', this.__boundUpdateActive);
Expand Down Expand Up @@ -144,11 +163,6 @@ class SideNavItem extends ElementMixin(ThemableMixin(PolylitMixin(LitElement)))
`;
}

/** @private */
__pathChanged() {
this.__updateActive();
}

/** @private */
__toggleExpanded(e) {
e.preventDefault();
Expand Down
6 changes: 4 additions & 2 deletions packages/side-nav/src/vaadin-side-nav.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright (c) 2017 - 2023 Vaadin Ltd.
* Copyright (c) 2023 Vaadin Ltd.
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
import { LitElement } from 'lit';
Expand All @@ -21,6 +21,7 @@ export type SideNavEventMap = HTMLElementEventMap & SideNavCustomEventMap;

/**
* `<vaadin-side-nav>` is a Web Component for navigation menus.
*
* ```html
* <vaadin-side-nav>
* <vaadin-side-nav-item>Item 1</vaadin-side-nav-item>
Expand All @@ -38,7 +39,8 @@ export type SideNavEventMap = HTMLElementEventMap & SideNavCustomEventMap;
* ----------|-------------
* `label` | The label (text) inside the side nav.
*
* #### Example:
* #### Example
*
* ```html
* <vaadin-side-nav>
* <span slot="label">Main menu</span>
Expand Down
9 changes: 4 additions & 5 deletions packages/side-nav/src/vaadin-side-nav.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/**
* @license
* Copyright (c) 2017 - 2023 Vaadin Ltd.
* Copyright (c) 2023 Vaadin Ltd.
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/

import { html, LitElement } from 'lit';
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
Expand All @@ -17,6 +16,7 @@ function isEnabled() {

/**
* `<vaadin-side-nav>` is a Web Component for navigation menus.
*
* ```html
* <vaadin-side-nav>
* <vaadin-side-nav-item>Item 1</vaadin-side-nav-item>
Expand All @@ -34,7 +34,8 @@ function isEnabled() {
* ----------|-------------
* `label` | The label (text) inside the side nav.
*
* #### Example:
* #### Example
*
* ```html
* <vaadin-side-nav>
* <span slot="label">Main menu</span>
Expand Down Expand Up @@ -87,8 +88,6 @@ class SideNav extends ElementMixin(ThemableMixin(PolylitMixin(LitElement))) {

/** @protected */
firstUpdated() {
super.ready();

// By default, if the user hasn't provided a custom role,
// the role attribute is set to "navigation".
if (!this.hasAttribute('role')) {
Expand Down