Skip to content

Commit

Permalink
remove console logs + add focus trap to card component with prop cont…
Browse files Browse the repository at this point in the history
…rol + fix element for config badge button
  • Loading branch information
aalves08 committed Jan 13, 2025
1 parent 72a24bb commit f1f73c5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
28 changes: 27 additions & 1 deletion pkg/rancher-components/src/components/Card/Card.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import { defineComponent, PropType } from 'vue';
import { createFocusTrap } from 'focus-trap';
export default defineComponent({
name: 'Card',
Expand Down Expand Up @@ -50,12 +51,37 @@ export default defineComponent({
type: Boolean,
default: false,
},
}
triggerFocusTrap: {
type: Boolean,
default: false,
},
},
data() {
return { focusTrapInstance: undefined as any };

Check warning on line 60 in pkg/rancher-components/src/components/Card/Card.vue

View workflow job for this annotation

GitHub Actions / validate-lint

Unexpected any. Specify a different type

Check warning on line 60 in pkg/rancher-components/src/components/Card/Card.vue

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
},
mounted() {
if (this.triggerFocusTrap) {
this.focusTrapInstance = createFocusTrap(this.$refs.cardContainer as HTMLElement, {
escapeDeactivates: true,
allowOutsideClick: true,
});
this.$nextTick(() => {
this.focusTrapInstance.activate();
});
}
},
beforeUnmount() {
if (this.focusTrapInstance && this.triggerFocusTrap) {
this.focusTrapInstance.deactivate();
}
},
});
</script>

<template>
<div
ref="cardContainer"
class="card-container"
:class="{'highlight-border': showHighlightBorder, 'card-sticky': sticky}"
data-testid="card"
Expand Down
13 changes: 12 additions & 1 deletion shell/components/Tabbed/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ export default {
role="tablist"
class="tabs"
:class="{'clearfix':!sideTabs, 'vertical': sideTabs, 'horizontal': !sideTabs}"
tabindex="0"
data-testid="tabbed-block"
@keydown.right.prevent="selectNext(1)"
@keydown.left.prevent="selectNext(-1)"
Expand All @@ -277,8 +276,12 @@ export default {
:data-testid="`btn-${tab.name}`"
:aria-controls="'#' + tab.name"
:aria-selected="tab.active"
:aria-label="tab.labelDisplay"
role="tab"
tabindex="0"
@click.prevent="select(tab.name, $event)"
@keyup.enter="select(tab.name, $event)"
@keyup.space="select(tab.name, $event)"
>
<span>{{ tab.labelDisplay }}</span>
<span
Expand Down Expand Up @@ -403,6 +406,14 @@ export default {
text-decoration: underline;
}
}
&:focus-visible {
@include focus-outline;
span {
text-decoration: underline;
}
}
}
.conditions-alert-icon {
Expand Down
2 changes: 1 addition & 1 deletion shell/dialog/AddCustomBadgeDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ export default {
<template>
<Card
v-trap="true"
class="prompt-badge"
:show-highlight-border="false"
:trigger-focus-trap="true"
>
<template #title>
<h4 class="text-default-text">
Expand Down
1 change: 0 additions & 1 deletion shell/directives/focus-trap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createFocusTrap } from 'focus-trap';

console.error('RUNNING!!!!');
let trap;

const createTrap = (element) => {
Expand Down
7 changes: 3 additions & 4 deletions shell/pages/c/_cluster/explorer/ConfigBadge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default {
}
},
methods: {
customBadgeDialog() {
customBadgeDialog(ev) {
this.$store.dispatch('cluster/promptModal', { component: 'AddCustomBadgeDialog', componentProps: { mode: _EDIT } });
},
},
Expand All @@ -28,20 +28,19 @@ export default {
class="config-badge"
>
<div>
<a
<button
class="badge-install btn btn-sm role-secondary"
data-testid="add-custom-cluster-badge"
role="button"
tabindex="0"
@click="customBadgeDialog"
@keyup.enter="customBadgeDialog"
@keyup.space="customBadgeDialog"
>
<i
v-clean-tooltip="tooltip"
class="icon icon-brush-icon"
/>
</a>
</button>
</div>
</div>
</template>
Expand Down

0 comments on commit f1f73c5

Please sign in to comment.