Skip to content
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
112 changes: 70 additions & 42 deletions plugins/CoreHome/vue/dist/CoreHome.umd.js

Large diffs are not rendered by default.

58 changes: 29 additions & 29 deletions plugins/CoreHome/vue/dist/CoreHome.umd.min.js

Large diffs are not rendered by default.

62 changes: 46 additions & 16 deletions plugins/CoreHome/vue/src/ExpandOnClick/ExpandOnClick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,64 @@ import DirectiveUtilities from '../directiveUtilities';
interface ExpandOnClickArgs {
// input (specified by user)
expander: string | HTMLElement,
onClosed?: () => void;
onClosed?: (event: MouseEvent|KeyboardEvent) => void;
onExpand?: (event: MouseEvent|KeyboardEvent) => void;

// state
isMouseDown?: boolean;
hasScrolled?: boolean;

// event handlers
onExpand?: () => void;
// internal event handlers
onClickOnExpander?: (event: MouseEvent|KeyboardEvent) => void;
onClickOutsideElement?: (event: MouseEvent) => void;
onScroll?: () => void;
onMouseDown?: () => void;
onEscapeHandler?: (event: KeyboardEvent) => void;
}

function onExpand(element: HTMLElement) {
element.classList.toggle('expanded');
function expand(
element: HTMLElement,
binding: DirectiveBinding<ExpandOnClickArgs>,
event: MouseEvent|KeyboardEvent,
) {
element.classList.add('expanded');
if (binding.value?.onExpand) {
binding.value.onExpand(event);
}

const positionElement = element.querySelector('.dropdown.positionInViewport');
if (positionElement) {
Matomo.helper.setMarginLeftToBeInViewport(positionElement);
}
}

function close(
element: HTMLElement,
binding: DirectiveBinding<ExpandOnClickArgs>,
event: MouseEvent|KeyboardEvent,
) {
if (!element.classList.contains('expanded')) {
return;
}
element.classList.remove('expanded');

if (binding.value?.onClosed) {
binding.value.onClosed(event);
}
}

function onClickOnExpander(
element: HTMLElement,
binding: DirectiveBinding<ExpandOnClickArgs>,
event: MouseEvent|KeyboardEvent,
) {
if (element.classList.contains('expanded')) {
close(element, binding, event);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ℹ️ Restructure this part because onExpand triggered a toggle, so it was also used to close without user event triggered.

} else {
expand(element, binding, event);
}
}

function onClickOutsideElement(
element: HTMLElement,
binding: DirectiveBinding<ExpandOnClickArgs>,
Expand All @@ -49,11 +84,7 @@ function onClickOutsideElement(
}

if (!element.contains(event.target as HTMLElement)) {
element.classList.remove('expanded');

if (binding.value?.onClosed) {
binding.value.onClosed();
}
close(element, binding, event);
}
}

Expand All @@ -71,15 +102,14 @@ function onEscapeHandler(
binding: DirectiveBinding<ExpandOnClickArgs>,
event: KeyboardEvent,
) {
if (event.which === 27) {
if (event.key === 'Escape') {
binding.value.isMouseDown = false;
binding.value.hasScrolled = false;
element.classList.remove('expanded');
close(element, binding, event);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ℹ️ There was no onClosed event triggered either here.

}
}

const doc = document.documentElement;
const { $ } = window;

/**
* Usage (in a component):
Expand All @@ -93,7 +123,7 @@ export default {
mounted(el: HTMLElement, binding: DirectiveBinding<ExpandOnClickArgs>): void {
binding.value.isMouseDown = false;
binding.value.hasScrolled = false;
binding.value.onExpand = onExpand.bind(null, el);
binding.value.onClickOnExpander = onClickOnExpander.bind(null, el, binding);
binding.value.onEscapeHandler = onEscapeHandler.bind(null, el, binding);
binding.value.onMouseDown = onMouseDown.bind(null, binding);
binding.value.onClickOutsideElement = onClickOutsideElement.bind(null, el, binding);
Expand All @@ -102,7 +132,7 @@ export default {
setTimeout(() => {
const expander = DirectiveUtilities.getRef(binding.value.expander, binding);
if (expander) {
$(expander).on('click', binding.value.onExpand!);
expander.addEventListener('click', binding.value.onClickOnExpander!);
}
});
doc.addEventListener('keyup', binding.value.onEscapeHandler);
Expand All @@ -113,7 +143,7 @@ export default {
unmounted(el: HTMLElement, binding: DirectiveBinding<ExpandOnClickArgs>): void {
const expander = DirectiveUtilities.getRef(binding.value.expander, binding);
if (expander) {
$(expander).off('click', binding.value.onExpand!);
doc.removeEventListener('click', binding.value.onClickOnExpander!);
}
doc.removeEventListener('keyup', binding.value.onEscapeHandler!);
doc.removeEventListener('mousedown', binding.value.onMouseDown!);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
}

.periodSelector-withPrevNext {
a.title {
button.title {
width: calc(~'100% - 40px');
text-align: center;

Expand Down
24 changes: 20 additions & 4 deletions plugins/CoreHome/vue/src/PeriodSelector/PeriodSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
ref="root"
class="periodSelector piwikSelector"
:class="{'periodSelector-withPrevNext': canShowMovePeriod}"
v-expand-on-click="{ expander: 'title' }"
v-expand-on-click="{
expander: 'title',
onExpand: onExpand,
onClosed: onClosed,
}"
>
<button
v-if="canShowMovePeriod"
Expand All @@ -21,17 +25,17 @@
<span class="icon-chevron-left"></span>
</button>

<a
<button
ref="title"
id="date"
class="title"
tabindex="-1"
tabindex="4"
v-tooltips
:title="translate('General_ChooseDate', currentlyViewingText)"
>
<span class="icon icon-calendar" />
{{ currentlyViewingText }}
</a>
</button>

<div
id="periodMore"
Expand Down Expand Up @@ -436,6 +440,18 @@ export default defineComponent({
},
},
methods: {
onExpand(event: MouseEvent|KeyboardEvent) {
const isKeyboardEvent = event.detail === 0;
if (isKeyboardEvent) {
window.$(this.$refs.root as HTMLElement).find('.ui-datepicker-month').focus();
}
},
onClosed(event: MouseEvent|KeyboardEvent) {
const isKeyboardEvent = event.detail === 0;
if (isKeyboardEvent) {
window.$(this.$refs.title as HTMLElement).focus();
}
},
handleZIndexPositionRelativeCompareDropdownIssue() {
const $element = window.$(this.$refs.root as HTMLElement);
$element.on('focus', '#comparePeriodToDropdown .select-dropdown', () => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion plugins/Dashboard/tests/UI/WidgetizedDashboard_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe("WidgetizedDashboard", function () {
it("should remove widget when remove widget icon is clicked", async function() {
await page.click('.ui-dialog-titlebar-close'); // close row evolution

var widget = '[id="widgetActionsgetPageUrls"]';
var widget = '#dashboardWidgetsArea [id="widgetActionsgetPageUrls"]';

var titlebar = await page.$(widget + ' .widgetTop');
await titlebar.hover();
Expand Down
4 changes: 3 additions & 1 deletion plugins/Morpheus/stylesheets/general/_default.less
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ a {
}

a:focus-visible,
button:focus-visible {
button:focus-visible,
input[type="button"]:focus-visible,
select:focus-visible {
outline: 2px solid @theme-color-focus-ring;
outline-offset: -2px;
}
Expand Down
5 changes: 5 additions & 0 deletions plugins/Morpheus/stylesheets/ui/_buttons.less
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ input[type="submit"].btn,
text-decoration: none;
}

&:focus-visible {
outline: 2px solid @theme-color-focus-ring;
outline-offset: -2px;
}

em {
font-style: normal;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/UI/expected-screenshots/PeriodSelector_closed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/UI/expected-screenshots/PeriodSelector_expanded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading