Skip to content

Commit 77174ec

Browse files
committed
Accessibility tweaks ...
- Preference stems off a single toggle. - Got rid of the accessibility tab now that there's only a single field. - Renamed the preference to strict_accessibility. If there's ever a new thing we need or want to adhere to, we can reuse the preference. - Contrast class doesn't need to worry about the preference changing. - Contrast class should update the data property, not a class. - Data property is added to the body tag without js too.
1 parent 15e7945 commit 77174ec

5 files changed

Lines changed: 15 additions & 57 deletions

File tree

resources/js/bootstrap/statamic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export default {
185185

186186
Object.assign(this.$app.config.globalProperties, {
187187
$theme: new Theme(this.initialConfig.user?.theme),
188-
$contrast: new Contrast(this.initialConfig.user?.preferences?.contrast),
188+
$contrast: new Contrast(this.initialConfig.user?.preferences?.strict_accessibility),
189189
});
190190

191191
Object.assign(this.$app.config.globalProperties, {

resources/js/components/Contrast.js

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,16 @@ export default class Contrast {
55
#contrast = ref(null);
66

77
constructor(preference) {
8-
this.#preference = ref(preference ?? 'default');
9-
this.#watchPreferences();
8+
this.#preference = ref(preference ? 'increased' : 'auto');
9+
this.#setContrast(this.#preference.value);
1010
this.#watchContrast();
1111
this.#listenForColorSchemeChange();
1212
}
1313

14-
get preference() {
15-
return this.#preference;
16-
}
17-
18-
set preference(value) {
19-
this.#preference.value = value;
20-
}
21-
22-
#watchPreferences() {
23-
watch(
24-
this.#preference,
25-
(preference) => {
26-
this.#setContrast(preference);
27-
this.#savePreference(preference);
28-
},
29-
{ immediate: true },
30-
);
31-
}
32-
3314
#watchContrast() {
3415
watch(
3516
this.#contrast,
36-
(contrast) => {
37-
document.documentElement.classList.toggle('contrast-increased', contrast === 'increased');
38-
},
17+
(contrast) => document.body.setAttribute('data-contrast', contrast),
3918
{ immediate: true },
4019
);
4120
}
@@ -52,14 +31,4 @@ export default class Contrast {
5231
if (this.#preference.value === 'auto') this.#contrast.value = e.matches ? 'increased' : 'default';
5332
});
5433
}
55-
56-
#savePreference(preference) {
57-
if (preference === 'default') {
58-
Statamic.$preferences.remove('contrast');
59-
localStorage.removeItem('statamic.contrast');
60-
} else {
61-
Statamic.$preferences.set('contrast', preference);
62-
localStorage.setItem('statamic.contrast', preference);
63-
}
64-
}
65-
}
34+
}

resources/views/layout.blade.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
@include('statamic::partials.head')
88
</head>
99

10-
<body class="bg-gray-800 font-sans leading-normal text-gray-900 dark:text-white">
10+
<body
11+
class="bg-gray-800 font-sans leading-normal text-gray-900 dark:text-white"
12+
@if ($user->getPreference('strict_accessibility')) data-contrast="increased" @endif
13+
>
1114
<config-provider>
1215
<div id="statamic" v-cloak>
1316
@include('statamic::partials.session-expiry')

resources/views/partials/head.blade.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
if (theme === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches) theme = 'dark';
2828
if (theme === 'dark') document.documentElement.classList.add('dark');
2929
30-
let contrast = {!! ($userContrast = $user?->preferences()['contrast'] ?? null) ? "'" . $userContrast . "'" : 'null' !!};
31-
if (!contrast) contrast = localStorage.getItem('statamic.contrast') ?? 'default';
30+
let contrast = {!! $user?->getPreference('strict_accessibility') ? "'increased'" : "'auto'" !!};
3231
if (contrast === 'auto' && window.matchMedia('(prefers-contrast: more)').matches) contrast = 'increased';
3332
if (contrast === 'increased') document.documentElement.setAttribute('data-contrast', 'increased');
3433
})();

src/Preferences/CorePreferences.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,11 @@ public function boot()
2525
'instructions' => __('statamic::messages.preference_start_page_instructions'),
2626
]);
2727

28-
Preference::tab('accessibility', __('Accessibility'), function () {
29-
Preference::register('wcag_conformity', [
30-
'type' => 'toggle',
31-
'display' => __('Strict WCAG 2.2 Conformity'),
32-
'instructions' => __('statamic::messages.preference_wcag'),
33-
]);
34-
Preference::register('contrast', [
35-
'type' => 'button_group',
36-
'display' => __('Increase Contrast'),
37-
'instructions' => __('statamic::messages.preference_contrast'),
38-
'default' => 'default',
39-
'options' => [
40-
'default' => __('Default'),
41-
'increased' => __('Increased'),
42-
'auto' => __('System'),
43-
],
44-
]);
45-
});
28+
Preference::register('strict_accessibility', [
29+
'type' => 'toggle',
30+
'display' => __('Strict WCAG 2.2 Conformity'),
31+
'instructions' => __('statamic::messages.preference_wcag'),
32+
]);
4633
}
4734

4835
private function localeOptions(): array

0 commit comments

Comments
 (0)