-
Notifications
You must be signed in to change notification settings - Fork 275
feat(ui5-side-navigation): initial implementation #1889
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
776f98a
feat(ui5-side-navigation): initial implementation
fifoosid c706570
implement kbh & collapse/expand behaviour
fifoosid c4410c1
implement events
fifoosid db8f9b6
add samples & docs
fifoosid 94887af
refactor icons
fifoosid d7a9c92
fix comments
fifoosid f444d10
wip
fifoosid b75e828
finish implementation
fifoosid 1a19ffc
move to fiori package, add tests, fix comments
fifoosid 3c9dc6d
fix comments and styling issues
fifoosid a64bcf1
fix background
fifoosid d89a614
Merge remote-tracking branch 'origin/master' into side-navigation
vladitasev 3ad734a
simplification and disambiguation
vladitasev d55bb10
remove unnecessary parameters and functions
vladitasev 7b3d14f
delete level
vladitasev ccb96d9
delete expandable 1
vladitasev f43dbc8
use existing tree function, fix module imports help
vladitasev 941651b
delete expandable - it is the same as showToggleButton
vladitasev 14cf96c
move _collapsed and _showToggleButtonEnd to tree level and don't pass…
vladitasev ff7b909
fix for IE: do not override the CSS var, directly override width instead
vladitasev e7236df
selected state fixed
vladitasev d7df553
Merge branch 'master' into side-navigation
fifoosid 45c2d28
apply invalidateParent & fix failing tests
fifoosid 9b37a3b
selected can be changed programmatically
vladitasev 63fb073
remove _selectedItem
vladitasev 49e3ab3
make fixed items nestable & fix event firing for collapsed items
fifoosid 8c0620d
fix comments
fifoosid 8ed1eec
fix bug: cannot select fixed subitem
vladitasev 44f89f1
slots docs, support for .hbs hooks, fix spacers in hbs
vladitasev 23f5b50
sample fix
vladitasev d632e4c
add min height to the spacer for scenarios with many items
vladitasev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<title>Shell Bar</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> | ||
|
||
<script data-ui5-config type="application/json"> | ||
{ | ||
"rtl": false | ||
} | ||
</script> | ||
|
||
<script src="../../webcomponentsjs/webcomponents-loader.js"></script> | ||
<script src="../../resources/bundle.esm.js" type="module"></script> | ||
<script nomodule src="../../resources/bundle.es5.js"></script> | ||
|
||
<style> | ||
html, body { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
body { | ||
height: 100vh; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body style="background-color: var(--sapBackgroundColor);"> | ||
<ui5-shellbar | ||
primary-title="UI5 Web Components" | ||
secondary-title="The Best Run SAP" | ||
show-co-pilot | ||
> | ||
<ui5-button icon="menu" slot="startButton" id="startButton"></ui5-button> | ||
</ui5-shellbar> | ||
|
||
<ui5-side-navigation> | ||
<ui5-side-navigation-item text="Home" icon="home"></ui5-side-navigation-item> | ||
<ui5-side-navigation-item text="People" expandable icon="group"> | ||
<ui5-side-navigation-item text="From My Team" icon="employee-approvals"></ui5-side-navigation-item> | ||
<ui5-side-navigation-item text="From Other Teams" icon="employee-rejections"></ui5-side-navigation-item> | ||
</ui5-side-navigation-item> | ||
<ui5-side-navigation-item text="Locations" icon="locate-me" selected></ui5-side-navigation-item> | ||
<ui5-side-navigation-item text="Events" expandable icon="calendar"> | ||
<ui5-side-navigation-item text="Local"></ui5-side-navigation-item> | ||
<ui5-side-navigation-item text="Others"></ui5-side-navigation-item> | ||
</ui5-side-navigation-item> | ||
|
||
<ui5-side-navigation-item slot="fixedItems" text="Usefull Links" icon="chain-link"></ui5-side-navigation-item> | ||
<ui5-side-navigation-item slot="fixedItems" text="History" icon="history"></ui5-side-navigation-item> | ||
</ui5-side-navigation> | ||
|
||
<script> | ||
var sideNavigation = document.querySelector("ui5-side-navigation"); | ||
document.querySelector("#startButton").addEventListener("click", function(event) { | ||
sideNavigation.collapsed = !sideNavigation.collapsed; | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<div class="ui5-sn-root"> | ||
{{#if items.length}} | ||
<div | ||
class="ui5-sn-content" | ||
@ui5-_click="{{handleItemClick}}" | ||
@ui5-_forward-focus="{{_focusOtherList}}" | ||
@ui5-_focus_next="{{focusNext}}" | ||
@ui5-_focus_previous="{{focusPrevious}}" | ||
> | ||
<div class="ui5-sn-flex-wrapper"> | ||
<slot></slot> | ||
</div> | ||
<span class="ui5-sn-middle-focus-helper" tabindex="-1"></span> | ||
</div> | ||
{{/if}} | ||
|
||
{{#if fixedItems.length}} | ||
<div class="ui5-sn-bottom-content"> | ||
<div class="ui5-sn-bottom-content-border"> | ||
<span></span> | ||
</div> | ||
<div | ||
class="ui5-sn-flex-wrapper" | ||
@ui5-_click="{{handleItemClick}}" | ||
@ui5-_return_focus="{{_focusOtherList}}" | ||
@ui5-_focus_next="{{focusNext}}" | ||
@ui5-_focus_previous="{{focusPrevious}}" | ||
> | ||
<slot name="fixedItems"></slot> | ||
</div> | ||
</div> | ||
{{/if}} | ||
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js"; | ||
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js"; | ||
import ResponsivePopover from "./ResponsivePopover.js"; | ||
import List from "./List.js"; | ||
import StandardListItem from "./StandardListItem.js"; | ||
import SideNavigationTemplate from "./generated/templates/SideNavigationTemplate.lit.js"; | ||
import SideNavigationItemPopoverContentTemplate from "./generated/templates/SideNavigationItemPopoverContentTemplate.lit.js"; | ||
|
||
// Styles | ||
import SideNavigationCss from "./generated/themes/SideNavigation.css.js"; | ||
|
||
/** | ||
* @public | ||
*/ | ||
const metadata = { | ||
tag: "ui5-side-navigation", | ||
managedSlots: true, | ||
properties: /** @lends sap.ui.webcomponents.main.SideNavigation.prototype */ { | ||
/** | ||
* Defines whether the <code>ui5-side-navigation</code> is expanded or collapsed. | ||
* | ||
* @public | ||
* @type {boolean} | ||
* @defaultvalue false | ||
*/ | ||
collapsed: { | ||
type: Boolean, | ||
}, | ||
|
||
_popoverContent: { | ||
type: Object, | ||
multiple: true, | ||
}, | ||
}, | ||
slots: /** @lends sap.ui.webcomponents.main.SideNavigation.prototype */ { | ||
/** | ||
* Defines the items in the <code>ui5-side-navigation</code>. | ||
* | ||
* @public | ||
fifoosid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @slot | ||
*/ | ||
"default": { | ||
propertyName: "items", | ||
type: HTMLElement, | ||
}, | ||
|
||
/** | ||
* Defines the fixed items in the bottom of the <code>ui5-side-navigation</code>. | ||
* | ||
* @public | ||
fifoosid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @slot | ||
*/ | ||
fixedItems: { | ||
type: HTMLElement, | ||
}, | ||
}, | ||
events: /** @lends sap.ui.webcomponents.main.SideNavigation.prototype */ { | ||
/** | ||
* Fired when the selection has changed via user interaction | ||
* | ||
* @event sap.ui.webcomponents.main.SideNavigation#selection-change | ||
* @param {HTMLElement} item the clicked item. | ||
* @public | ||
*/ | ||
"selection-change": { | ||
item: { | ||
type: HTMLElement, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
/** | ||
* @class | ||
* | ||
* <h3 class="comment-api-title">Overview</h3> | ||
* | ||
* | ||
* <h3>Usage</h3> | ||
* | ||
* <code>ui5-side-navigation</code> is used as a standard menu in applications. In order to add menu items use <code>ui5-side-navigation-items</code>. | ||
* | ||
* For the <code>ui5-side-navigation</code> | ||
* <h3>ES6 Module Import</h3> | ||
* | ||
* <code>import @ui5/webcomponents/dist/SideNavigation.js";</code> | ||
* | ||
* @constructor | ||
* @author SAP SE | ||
* @alias sap.ui.webcomponents.main.SideNavigation | ||
* @extends UI5Element | ||
* @tagname ui5-side-navigation | ||
* @since 1.0.0-rc.8 | ||
* @appenddocs SideNavigationItem | ||
* @public | ||
*/ | ||
class SideNavigation extends UI5Element { | ||
static get metadata() { | ||
return metadata; | ||
} | ||
|
||
static get render() { | ||
return litRender; | ||
} | ||
|
||
static get styles() { | ||
return SideNavigationCss; | ||
} | ||
|
||
static get template() { | ||
return SideNavigationTemplate; | ||
} | ||
|
||
static get staticAreaTemplate() { | ||
return SideNavigationItemPopoverContentTemplate; | ||
} | ||
|
||
static async onDefine() { | ||
await Promise.all([ | ||
fifoosid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ResponsivePopover.define(), | ||
List.define(), | ||
StandardListItem.define(), | ||
]); | ||
} | ||
|
||
onBeforeRendering() { | ||
this.items.forEach(item => { | ||
item._collapsed = this.collapsed; | ||
}); | ||
|
||
this.fixedItems.forEach(item => { | ||
item._collapsed = this.collapsed; | ||
}); | ||
} | ||
|
||
handleItemClick(event) { | ||
const currentItems = Array.from(this.querySelectorAll("ui5-side-navigation-item")); | ||
|
||
currentItems.forEach(item => { | ||
item.selected = item === event.target; | ||
}); | ||
|
||
this.fireSelectionChange(event); | ||
|
||
if (this.collapsed) { | ||
this.openPicker(event.target); | ||
this._popoverContent = event.target._generatePopoverContent(); | ||
} | ||
} | ||
|
||
fireSelectionChange(event) { | ||
const item = (event.detail && event.detail.item && event.detail.item.item) || event.target; | ||
const isArrowClicked = event.detail && event.detail.isIconClicked; | ||
|
||
this.fireEvent("selection-change", { | ||
item, | ||
isArrowClicked, | ||
}); | ||
} | ||
|
||
getMiddleFocusHelper() { | ||
return this.getDomRef().querySelector(".ui5-sn-middle-focus-helper"); | ||
} | ||
|
||
_focusOtherList() { | ||
this.getMiddleFocusHelper().focus(); | ||
} | ||
|
||
focusNext(event) { | ||
const eventTarget = event.target; | ||
ilhan007 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const isFixedItems = eventTarget.slot === "fixedItems"; | ||
let currentItems = Array.from(this.querySelectorAll(`ui5-side-navigation-item${isFixedItems ? "[slot='fixedItems']" : ":not([slot])"}`)); | ||
|
||
if (eventTarget.expandable && eventTarget.expanded) { | ||
eventTarget.items[0].focus(); | ||
} else if (currentItems.indexOf(eventTarget) > -1 && currentItems.indexOf(eventTarget) < currentItems.length - 1) { | ||
if (currentItems[currentItems.indexOf(eventTarget) + 1].getClientRects().length === 0) { | ||
currentItems = isFixedItems ? this.fixedItems : this.items; | ||
} | ||
const nextItem = currentItems[currentItems.indexOf(eventTarget) + 1]; | ||
|
||
if (nextItem) { | ||
nextItem.focus(); | ||
} | ||
} | ||
} | ||
|
||
focusPrevious(event) { | ||
const eventTarget = event.target; | ||
const isFixedItems = eventTarget.slot === "fixedItems"; | ||
let currentItems = Array.from(this.querySelectorAll(`ui5-side-navigation-item${isFixedItems ? "[slot='fixedItems']" : ":not([slot])"}`)); | ||
|
||
if (eventTarget.expandable && eventTarget.expanded) { | ||
const _prevItem = currentItems[currentItems.indexOf(eventTarget) - 1]; | ||
|
||
if (_prevItem) { | ||
_prevItem.focus(); | ||
} | ||
} else if (currentItems.indexOf(eventTarget) > 0) { | ||
if (currentItems[currentItems.indexOf(eventTarget) - 1].getClientRects().length === 0) { | ||
currentItems = isFixedItems ? this.fixedItems : this.items; | ||
} | ||
|
||
currentItems[currentItems.indexOf(eventTarget) - 1].focus(); | ||
} | ||
} | ||
|
||
async getPicker() { | ||
return (await this.getStaticAreaItemDomRef()).querySelector("ui5-responsive-popover"); | ||
} | ||
|
||
async openPicker(opener) { | ||
if (!opener.items.length) { | ||
return; | ||
} | ||
const responsivePopover = await this.getPicker(); | ||
|
||
responsivePopover.open(opener); | ||
} | ||
|
||
async closePicker() { | ||
const responsivePopover = await this.getPicker(); | ||
|
||
responsivePopover.close(); | ||
} | ||
} | ||
|
||
SideNavigation.define(); | ||
|
||
export default SideNavigation; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<div | ||
class="{{classes.root}}" | ||
tabindex="0" | ||
@mousedown="{{_onmousedown}}" | ||
@mouseup="{{_onmouseup}}" | ||
@focusin="{{_onfocusin}}" | ||
@focusout="{{_onfocusout}}" | ||
@keydown="{{_onkeydown}}" | ||
> | ||
{{#if icon}} | ||
<ui5-icon name="{{icon}}"></ui5-icon> | ||
{{/if}} | ||
|
||
{{#if hasOverflow}} | ||
<span class="ui5-sni-bottom-arrow"></span> | ||
{{/if}} | ||
|
||
<ui5-title level="H5">{{text}}</ui5-title> | ||
|
||
{{#if expandable}} | ||
<ui5-icon name="{{activeIcon}}" id="ui5-sni-expand-icon" class="ui5-sni-expand-icon"></ui5-icon> | ||
{{/if}} | ||
|
||
</div> | ||
{{#if showChildren}} | ||
<slot></slot> | ||
{{/if}} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
would not it work with standard @ click, instead of firing ui5-_click on mouseup