Skip to content

Commit

Permalink
color input is now key nav friendly + tooltip works on focus + trying…
Browse files Browse the repository at this point in the history
… to get focus trap to work properly
  • Loading branch information
aalves08 committed Jan 11, 2025
1 parent 71f40aa commit e671c29
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
11 changes: 9 additions & 2 deletions pkg/rancher-components/src/components/Form/Checkbox/Checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,15 @@ export default defineComponent({
<template v-else-if="label">{{ label }}</template>
<i
v-if="tooltipKey"
v-clean-tooltip="t(tooltipKey)"
v-clean-tooltip="{content: t(tooltipKey), triggers: ['hover', 'touch', 'focus']}"
class="checkbox-info icon icon-info icon-lg"
:tabindex="isDisabled ? -1 : 0"
/>
<i
v-else-if="tooltip"
v-clean-tooltip="tooltip"
v-clean-tooltip="{content: tooltip, triggers: ['hover', 'touch', 'focus']}"
class="checkbox-info icon icon-info icon-lg"
:tabindex="isDisabled ? -1 : 0"
/>
</slot>
</span>
Expand Down Expand Up @@ -319,6 +321,11 @@ $fontColor: var(--input-label);
.checkbox-info {
line-height: normal;
margin-left: 2px;
&:focus-visible {
@include focus-outline;
outline-offset: 2px;
}
}
.checkbox-custom {
Expand Down
1 change: 1 addition & 0 deletions shell/assets/translations/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ generic:
back: Back
cancel: Cancel
confirm: Confirm
colorPicker: Color picker
clear: Clear
clearAll: Clear All
close: Close
Expand Down
26 changes: 25 additions & 1 deletion shell/components/form/ColorInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,21 @@ export default {
mounted() {
// Ensures that if the default value is used, the model is updated with it
this.$emit('update:value', this.inputValue);
}
},
methods: {
handleKeyups(ev) {
if (this.isDisabled) {
return '';
}
return this.$refs.input.click(ev);
}
},
// according to https://www.w3.org/TR/html-aria/
// input type="color" has no applicable role
// and only aria-label and aria-disabled
};
</script>

Expand All @@ -82,6 +96,9 @@ export default {
class="color-input"
:class="{[mode]:mode, disabled: isDisabled}"
:data-testid="componentTestid + '-color-input'"
:tabindex="isDisabled ? -1 : 0"
@keyup.enter.stop="handleKeyups($event)"
@keyup.space.stop="handleKeyups($event)"
>
<label class="text-label"><t
v-if="labelKey"
Expand All @@ -99,8 +116,11 @@ export default {
>
<input
ref="input"
:aria-disabled="isDisabled ? 'true' : 'false'"
:aria-label="t('generic.colorPicker')"
type="color"
:disabled="isDisabled"
tabindex="-1"
:value="inputValue"
@input="$emit('update:value', $event.target.value)"
>
Expand All @@ -116,6 +136,10 @@ export default {
border-radius: var(--border-radius);
padding: 10px;
&:focus-visible {
@include focus-outline;
}
&.disabled, &.disabled .selected, &[disabled], &[disabled]:hover {
color: var(--input-disabled-text);
background-color: var(--input-disabled-bg);
Expand Down
9 changes: 8 additions & 1 deletion shell/dialog/AddCustomBadgeDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ export default {
<Checkbox
v-model:value="badgeAsIcon"
:label="t('clusterBadge.modal.badgeAsIcon')"
:tooltip="t('clusterBadge.modal.maxCharsTooltip')"
/>
Expand Down Expand Up @@ -313,15 +312,23 @@ export default {
/>
<div class="buttons">
<button
role="button"
class="btn role-secondary mr-10"
:aria-label="t('generic.cancel')"
@click="close"
@keyup.enter="close"
@keyup.space="close"
>
{{ t('generic.cancel') }}
</button>
<AsyncButton
:action-label="t('clusterBadge.modal.buttonAction')"
:disabled="!canSubmit"
role="button"
:aria-label="t('generic.cancel')"
@click="apply"
@keyup.enter="apply"
@keyup.space="apply"
/>
</div>
</div>
Expand Down

0 comments on commit e671c29

Please sign in to comment.