From 8649d87aba3b8c41c9f539cbe0665f3269be0a5e Mon Sep 17 00:00:00 2001 From: Teodor Taushanov Date: Wed, 28 Jul 2021 17:15:53 +0300 Subject: [PATCH 1/9] feat(ui5-carousel): Implement F7 keyboard functionality --- packages/base/hash.txt | 2 +- packages/main/src/Carousel.hbs | 1 + packages/main/src/Carousel.js | 68 +++++++++++++++++++++++++- packages/main/test/pages/Carousel.html | 45 +++++++++++++++++ 4 files changed, 114 insertions(+), 2 deletions(-) diff --git a/packages/base/hash.txt b/packages/base/hash.txt index d4c2bddc6733..d46cedb5e3ff 100644 --- a/packages/base/hash.txt +++ b/packages/base/hash.txt @@ -1 +1 @@ -Jo7xX6Xqjqd/+p/wSl0hl57d8ng= +Wn536C9eiynPZolKtePcgMFYAck= \ No newline at end of file diff --git a/packages/main/src/Carousel.hbs b/packages/main/src/Carousel.hbs index a4cf1b8c2046..a399d028501f 100644 --- a/packages/main/src/Carousel.hbs +++ b/packages/main/src/Carousel.hbs @@ -3,6 +3,7 @@ tabindex="0" role="listbox" aria-activedescendant="{{ariaActiveDescendant}}" + @focusin="{{_onfocusin}}" @keydown={{_onkeydown}} @mouseout="{{_onmouseout}}" @mouseover="{{_onmouseover}}" diff --git a/packages/main/src/Carousel.js b/packages/main/src/Carousel.js index 56579158ccb9..ebb2c5a59f92 100644 --- a/packages/main/src/Carousel.js +++ b/packages/main/src/Carousel.js @@ -6,6 +6,7 @@ import { isRight, isDown, isUp, + isF7, } from "@ui5/webcomponents-base/dist/Keys.js"; import { fetchI18nBundle, @@ -13,6 +14,7 @@ import { } from "@ui5/webcomponents-base/dist/i18nBundle.js"; import ScrollEnablement from "@ui5/webcomponents-base/dist/delegate/ScrollEnablement.js"; import ResizeHandler from "@ui5/webcomponents-base/dist/delegate/ResizeHandler.js"; +import { renderFinished } from "@ui5/webcomponents-base/dist/Render.js"; import { isDesktop } from "@ui5/webcomponents-base/dist/Device.js"; import AnimationMode from "@ui5/webcomponents-base/dist/types/AnimationMode.js"; import { getAnimationMode } from "@ui5/webcomponents-base/dist/config/AnimationMode.js"; @@ -285,6 +287,9 @@ class Carousel extends UI5Element { this.i18nBundle = getI18nBundle("@ui5/webcomponents"); this._onResizeBound = this._onResize.bind(this); this._resizing = false; // indicates if the carousel is in process of resizing + + this._lastFocusedElements = []; + this._orderOfLastFocusedPages = [] } onBeforeRendering() { @@ -348,15 +353,53 @@ class Carousel extends UI5Element { } } - _onkeydown(event) { + async _onkeydown(event) { + if (isF7(event)) { + this._handleF7Key(event); + return; + } + if (event.target !== this.getDomRef()) { return; } if (isLeft(event) || isDown(event)) { this.navigateLeft(); + await renderFinished(); + this.getDomRef().focus(); } else if (isRight(event) || isUp(event)) { this.navigateRight(); + await renderFinished(); + this.getDomRef().focus(); + } + } + + _onfocusin(event) { + if (event.target === this.getDomRef()) { + return; + } + + let pageIndex = -1; + + for (let i = 0; i < this.content.length; i++) { + if (this.content[i].contains(event.target)) { + pageIndex = i; + break; + } + } + + if (pageIndex === -1) { + return; + } + + // Save reference of the last focused element for each page + this._lastFocusedElements[pageIndex] = event.target; + + let sortedPageIndex = this._orderOfLastFocusedPages.indexOf(pageIndex); + if (sortedPageIndex === -1) { + this._orderOfLastFocusedPages.unshift(pageIndex); + } else { + this._orderOfLastFocusedPages.splice(0, 0, this._orderOfLastFocusedPages.splice(sortedPageIndex, 1)[0]); } } @@ -372,6 +415,29 @@ class Carousel extends UI5Element { } } + _handleF7Key(event) { + let lastFocusedElement = this._lastFocusedElements[this._getLastFocusedActivePageIndex]; + + if (event.target === this.getDomRef() && lastFocusedElement) { + lastFocusedElement.focus(); + } else { + this.getDomRef().focus(); + } + } + + get _getLastFocusedActivePageIndex() { + for (let i = 0; i < this._orderOfLastFocusedPages.length; i++) { + + let pageIndex = this._orderOfLastFocusedPages[i]; + + if (this.isItemInViewport(pageIndex)) { + return pageIndex; + } + } + + return this._selectedIndex; + }; + navigateLeft() { this._resizing = false; diff --git a/packages/main/test/pages/Carousel.html b/packages/main/test/pages/Carousel.html index b8f31eaabca6..62edfa597ebf 100644 --- a/packages/main/test/pages/Carousel.html +++ b/packages/main/test/pages/Carousel.html @@ -26,6 +26,51 @@ } + + +
+ Page 1 + + +
+
+ +
+ Page 2 + + +
+
+ +
+ Page 3 + + +
+
+ +
+ Page 4 + + +
+
+ +
+ Page 5 + + +
+
+ +
+ Page 6 + + +
+
+
+ From 3da2474eba27bed7dc26fa1db4a7e37daab3642f Mon Sep 17 00:00:00 2001 From: Teodor Taushanov Date: Wed, 28 Jul 2021 17:56:52 +0300 Subject: [PATCH 2/9] fix lint errors --- packages/main/src/Carousel.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/main/src/Carousel.js b/packages/main/src/Carousel.js index ebb2c5a59f92..fb5b6e80e5b3 100644 --- a/packages/main/src/Carousel.js +++ b/packages/main/src/Carousel.js @@ -289,7 +289,7 @@ class Carousel extends UI5Element { this._resizing = false; // indicates if the carousel is in process of resizing this._lastFocusedElements = []; - this._orderOfLastFocusedPages = [] + this._orderOfLastFocusedPages = []; } onBeforeRendering() { @@ -395,7 +395,7 @@ class Carousel extends UI5Element { // Save reference of the last focused element for each page this._lastFocusedElements[pageIndex] = event.target; - let sortedPageIndex = this._orderOfLastFocusedPages.indexOf(pageIndex); + const sortedPageIndex = this._orderOfLastFocusedPages.indexOf(pageIndex); if (sortedPageIndex === -1) { this._orderOfLastFocusedPages.unshift(pageIndex); } else { @@ -416,7 +416,7 @@ class Carousel extends UI5Element { } _handleF7Key(event) { - let lastFocusedElement = this._lastFocusedElements[this._getLastFocusedActivePageIndex]; + const lastFocusedElement = this._lastFocusedElements[this._getLastFocusedActivePageIndex]; if (event.target === this.getDomRef() && lastFocusedElement) { lastFocusedElement.focus(); @@ -427,7 +427,6 @@ class Carousel extends UI5Element { get _getLastFocusedActivePageIndex() { for (let i = 0; i < this._orderOfLastFocusedPages.length; i++) { - let pageIndex = this._orderOfLastFocusedPages[i]; if (this.isItemInViewport(pageIndex)) { @@ -436,7 +435,7 @@ class Carousel extends UI5Element { } return this._selectedIndex; - }; + } navigateLeft() { this._resizing = false; From fc3e1e2c680fb8710ef6d5716a50afb5a4cb20e0 Mon Sep 17 00:00:00 2001 From: Teodor Taushanov Date: Thu, 29 Jul 2021 15:57:55 +0300 Subject: [PATCH 3/9] fix lint errors --- packages/main/src/Carousel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/main/src/Carousel.js b/packages/main/src/Carousel.js index fb5b6e80e5b3..8d9462a3d867 100644 --- a/packages/main/src/Carousel.js +++ b/packages/main/src/Carousel.js @@ -427,7 +427,7 @@ class Carousel extends UI5Element { get _getLastFocusedActivePageIndex() { for (let i = 0; i < this._orderOfLastFocusedPages.length; i++) { - let pageIndex = this._orderOfLastFocusedPages[i]; + const pageIndex = this._orderOfLastFocusedPages[i]; if (this.isItemInViewport(pageIndex)) { return pageIndex; From 02fa39a9dc2435350d571d3e31e76ed9e6901588 Mon Sep 17 00:00:00 2001 From: Teodor Taushanov Date: Thu, 29 Jul 2021 16:07:38 +0300 Subject: [PATCH 4/9] update test page --- packages/main/test/pages/Carousel.html | 110 ++++++++++++++----------- 1 file changed, 64 insertions(+), 46 deletions(-) diff --git a/packages/main/test/pages/Carousel.html b/packages/main/test/pages/Carousel.html index 62edfa597ebf..ddaa2c25fbde 100644 --- a/packages/main/test/pages/Carousel.html +++ b/packages/main/test/pages/Carousel.html @@ -25,52 +25,6 @@ height: 100%; } - - - -
- Page 1 - - -
-
- -
- Page 2 - - -
-
- -
- Page 3 - - -
-
- -
- Page 4 - - -
-
- -
- Page 5 - - -
-
- -
- Page 6 - - -
-
-
- @@ -523,6 +477,70 @@ Button 3 + F7 keyboard navigation testing + + +
+ Page 1
+ Button 1 +
+ Button 2 +
+ +
+
+ +
+ Page 2
+ Button 1 +
+ Button 2 +
+ +
+
+ +
+ Page 3
+ Button 1 +
+ Button 2 +
+ +
+
+ +
+ Page 4
+ Button 1 +
+ Button 2 +
+ +
+
+ +
+ Page 5
+ Button 1 +
+ Button 2 +
+ +
+
+ +
+ Page 6
+ Button 1 +
+ Button 2 +
+ +
+
+
+