Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(table): support w3c WAI-ARIA (a11y) pattern #1135

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion packages/docs/components/Loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
| iconSpin | Enable spin effect on icon | boolean | - | <div><small>From <b>config</b>:</small></div><code style='white-space: nowrap; padding: 0;'>loading: {<br>&nbsp;&nbsp;iconSpin: true<br>}</code> |
| label | Notification label, unnecessary when default slot is used. | string | - | |
| override | Override existing theme classes completely | boolean | - | |
| scroll | Use `clip` to remove the body scrollbar, `keep` to have a non scrollable scrollbar to avoid shifting background,<br/>but will set body to position fixed, might break some layouts. | "clip" \| "keep" | `keep`, `clip` | <div><small>From <b>config</b>:</small></div><code style='white-space: nowrap; padding: 0;'>modal: {<br>&nbsp;&nbsp;scroll: "keep"<br>}</code> |
| role | Role attribute to be passed to the div wrapper for better accessibility | string | - | <div><small>From <b>config</b>:</small></div><code style='white-space: nowrap; padding: 0;'>loading: {<br>&nbsp;&nbsp;role: "dialog"<br>}</code> |
| scroll | Use `clip` to remove the body scrollbar, `keep` to have a non scrollable scrollbar to avoid shifting background,<br/>but will set body to position fixed, might break some layouts. | "clip" \| "keep" | `keep`, `clip` | <div><small>From <b>config</b>:</small></div><code style='white-space: nowrap; padding: 0;'>loading: {<br>&nbsp;&nbsp;scroll: "keep"<br>}</code> |

### Events

Expand Down
66 changes: 33 additions & 33 deletions packages/docs/components/Table.md

Large diffs are not rendered by default.

33 changes: 23 additions & 10 deletions packages/oruga/src/components/autocomplete/Autocomplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
triggerRef,
watchEffect,
useTemplateRef,
toValue,
type Component,
type MaybeRefOrGetter,
} from "vue";

import OInput from "../input/Input.vue";
Expand All @@ -27,11 +29,11 @@ import {
toOptionsList,
findOption,
checkOptionsEmpty,
firstValidOption,
firstViableOption,
filterOptionsItems,
useInputHandler,
useEventListener,
isOptionValid,
isOptionViable,
useSequentialId,
} from "@/composables";

Expand Down Expand Up @@ -224,11 +226,23 @@ const groupedOptions = computed<OptionsGroupItem<T>[]>(() => {
*/
watchEffect(() => {
// filter options by input value
filterOptionsItems(groupedOptions, inputValue, props.filter);
filterOptionsItems(groupedOptions, (o) => filterItems(o, inputValue));
// trigger reactive update of groupedOptions
triggerRef(groupedOptions);
});

function filterItems(
option: OptionsItem<T>,
value: MaybeRefOrGetter<string>,
): boolean {
if (typeof props.filter === "function")
return props.filter(option.value, toValue(value));
else
return !String(option.label)
.toLowerCase()
.includes(toValue(value)?.toLowerCase());
}

// set initial inputValue if selected is given
if (selectedValue.value) {
const selectedOption = findOption(groupedOptions, selectedValue);
Expand Down Expand Up @@ -361,7 +375,7 @@ function setHovered(option: OptionsItem<T> | SpecialOption | undefined): void {

/** set first option as hovered */
function hoverFirstOption(): void {
const option = firstValidOption(groupedOptions);
const option = firstViableOption(groupedOptions);
// set found option or undefined hovered
setHovered(option);
}
Expand All @@ -372,7 +386,7 @@ function hoverFirstOption(): void {
* Arrows keys listener.
* If dropdown is active, set hovered option, or else just open.
*/
function navigateItem(direction: 1 | -1): void {
function navigateItem(delta: 1 | -1): void {
if (!dropdownRef.value?.$content) return;
if (!isActive.value) {
isActive.value = true;
Expand All @@ -383,7 +397,7 @@ function navigateItem(direction: 1 | -1): void {
const options: OptionsItem<T>[] = toOptionsList(groupedOptions);
// filter only avaibale options
const availableOptions: (SpecialOption | OptionsItem<T>)[] = options.filter(
(o) => isOptionValid(o),
(o) => isOptionViable(o),
);

// item elements
Expand All @@ -401,15 +415,14 @@ function navigateItem(direction: 1 | -1): void {

// define current available options index
let index: number;
if (headerHovered.value) index = 0 + direction;
else if (footerHovered.value)
index = availableOptions.length - 1 + direction;
if (headerHovered.value) index = 0 + delta;
else if (footerHovered.value) index = availableOptions.length - 1 + delta;
else {
index =
availableOptions.findIndex(
(o) =>
!isSpecialOption(o) && o.key === hoveredOption.value?.key,
) + direction;
) + delta;
}

// check if index overflow
Expand Down
5 changes: 3 additions & 2 deletions packages/oruga/src/components/loading/Loading.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const props = withDefaults(defineProps<LoadingProps>(), {
icon: () => getDefault("loading.icon", "loading"),
iconSpin: () => getDefault("loading.iconSpin", true),
iconSize: () => getDefault("loading.iconSize", "medium"),
scroll: () => getDefault("modal.scroll", "keep"),
scroll: () => getDefault("loading.scroll", "keep"),
role: () => getDefault("loading.role", "dialog"),
});

const emits = defineEmits<{
Expand Down Expand Up @@ -127,7 +128,7 @@ defineExpose({ close });
v-if="isActive"
ref="rootElement"
data-oruga="loading"
role="dialog"
:role="role"
:class="rootClasses">
<div
:class="overlayClasses"
Expand Down
2 changes: 2 additions & 0 deletions packages/oruga/src/components/loading/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export type LoadingProps = {
* @values keep, clip
*/
scroll?: "keep" | "clip";
/** Role attribute to be passed to the div wrapper for better accessibility */
role?: string;
} & LoadingClasses;

// class props (will not be displayed in the docs)
Expand Down
Loading
Loading