Skip to content

Commit

Permalink
fix(telekom-profile-menu): keyboard accessibility & optional logout h…
Browse files Browse the repository at this point in the history
…andler (#2306)

* fix(app-navigation-user-menu): keyboard activation of links & buttons

* fix(app-navigation-user-menu): optional clickHandler for logout button

* fix(app-navigation-user-menu): mention clickHandler property in storybook

* fix(app-navigation-user-menu): fixed link to component description in storybook

* fix(telekom-profile-menu): mention new optional logoutHandler in readme
  • Loading branch information
tallence-dsulyok authored Apr 12, 2024
1 parent 2ad95bd commit bb7aabd
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ export class AppNavigationUserMenu {
}}
onKeyDown={(e) => {
if ([' ', 'Enter'].includes(e.key)) {
e.stopImmediatePropagation();
e.preventDefault();

if (item.onClick) {
e.stopImmediatePropagation();
e.preventDefault();
item.onClick(e);
}
this.hide();
Expand Down Expand Up @@ -128,16 +127,17 @@ export class AppNavigationUserMenu {
part="button"
onClick={(e) => {
if (item.onClick) {
e.stopImmediatePropagation();
e.preventDefault();
item.onClick(e);
}
this.hide();
}}
onKeyDown={(e) => {
if ([' ', 'Enter'].includes(e.key)) {
e.stopImmediatePropagation();
e.preventDefault();

if (item.onClick) {
e.stopImmediatePropagation();
e.preventDefault();
item.onClick(e);
}
this.hide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
| `loginSettingsLabel` | `login-settings-label` | | `string` | `undefined` |
| `loginSettingsUrl` | `login-settings-url` | | `string` | `undefined` |
| `loginUrl` | `login-url` | | `string` | `undefined` |
| `logoutHandler` | `logout-handler` | | `string` | `undefined` |
| `logoutLabel` | `logout-label` | | `string` | `undefined` |
| `logoutUrl` | `logout-url` | | `string` | `undefined` |
| `registerHeadline` | `register-headline` | | `string` | `undefined` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class TelekomProfileMenu {

@Prop() logoutLabel: string;
@Prop() logoutUrl?: string;
@Prop() logoutHandler?: string;

@State()
menuOpen = false;
Expand Down Expand Up @@ -161,6 +162,16 @@ export class TelekomProfileMenu {
);
}

buildLogoutButton() {
return {
type: 'button',
name: this.logoutLabel,
href: this.logoutUrl || LOGOUT_DEFAULT,
variant: 'secondary',
onClick: this.logoutHandler,
};
}

buildUserNavigation() {
const divider = [{ type: 'divider' }];

Expand All @@ -187,13 +198,6 @@ export class TelekomProfileMenu {
icon: 'service-settings',
};

const logout = {
type: 'button',
name: this.logoutLabel,
href: this.logoutUrl || LOGOUT_DEFAULT,
variant: 'secondary',
};

let menu = [];

menu = menu.concat(userInfo);
Expand All @@ -211,7 +215,7 @@ export class TelekomProfileMenu {
menu = menu.concat(divider);
}

menu = menu.concat(logout);
menu = menu.concat(this.buildLogoutButton());

return menu;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,11 @@ window.onload = () => {
email: '[email protected]',
});
profileMenu.serviceLinks = JSON.stringify(serviceLinks);
// optional: set a custom handler for clicks on logout button
profileMenu.logoutHandler = () => {
// ...
}
};
</script>
```
Expand Down Expand Up @@ -605,6 +610,11 @@ window.onload = () => {
email: '[email protected]',
});
profileMenu.serviceLinks = JSON.stringify(serviceLinks);
// optional: set a custom handler for clicks on logout button
profileMenu.logoutHandler = () => {
// ...
}
};
</script>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@ This component is still in the beta phase. When testing it, keep in mind that it
- [Sidebar Navigation](?path=/usage/components-sidebar-navigation--standard)
- [Tab Navigation](?path=/usage/components-tab-navigation--text-icon)
- [Accordion](?path=/usage/components-accordion--standard)
- [Profile Menu](?path=/docs/components-telekom-profile-menu--logged-out)
- [Profile Menu](?path=/docs/components-telekom-brand-header-navigation--profile-menu-logged-out)
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,4 @@ Diese Komponente befindet sich noch im Beta-Stadium. Wenn du sie testest, bedenk
- [Sidebar Navigation](?path=/usage/components-sidebar-navigation--standard)
- [Tab Navigation](?path=/usage/components-tab-navigation--text-icon)
- [Accordion](?path=/usage/components-accordion--standard)
- [Profile Menu](?path=/docs/components-telekom-profile-menu--logged-out)
- [Profile Menu](?path=/docs/components-telekom-brand-header-navigation--profile-menu-logged-out)

0 comments on commit bb7aabd

Please sign in to comment.