web/SettingsInput: better screen reader accessibility

aria-label is now read instead of placeholders, cuz lengthy ones like uuid are a sensory overload and could confuse people. instead, now we make a fake ui placeholder (because there's no other way to have exclusively aria-label while also showing placeholder normally)
This commit is contained in:
wukko 2024-11-24 00:12:35 +06:00
parent 6129198024
commit 0b6270e745
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2
3 changed files with 28 additions and 9 deletions

View file

@ -115,9 +115,12 @@
"processing.community": "community instances", "processing.community": "community instances",
"processing.enable_custom.title": "use a custom processing server", "processing.enable_custom.title": "use a custom processing server",
"processing.enable_custom.description": "cobalt will use a custom processing server if you choose to. even though cobalt has some security measures in place, we are not responsible for any damages done via a community instance, as we have no control over them.\n\nplease be mindful of what instances you use and make sure they're hosted by people you trust.", "processing.enable_custom.description": "cobalt will use a custom processing instance if you choose to. even though cobalt has some security measures in place, we are not responsible for any damages done via a community instance, as we have no control over them.\n\nplease be mindful of what instances you use and make sure they're hosted by people you trust.",
"processing.access_key": "instance access key", "processing.access_key": "instance access key",
"processing.access_key.title": "use an instance access key", "processing.access_key.title": "use an instance access key",
"processing.access_key.description": "cobalt will use this key to make requests to the processing instance instead of other authentication methods. make sure the instance supports api keys!" "processing.access_key.description": "cobalt will use this key to make requests to the processing instance instead of other authentication methods. make sure the instance supports api keys!",
"processing.custom_instance.input.alt_text": "custom instance domain",
"processing.access_key.input.alt_text": "u-u-i-d access key"
} }

View file

@ -18,6 +18,7 @@
export let settingId: Id; export let settingId: Id;
export let settingContext: Context; export let settingContext: Context;
export let placeholder: string; export let placeholder: string;
export let altText: string;
export let type: "url" | "uuid" = "url"; export let type: "url" | "uuid" = "url";
export let showInstanceWarning = false; export let showInstanceWarning = false;
@ -27,11 +28,9 @@
}; };
let input: HTMLInputElement; let input: HTMLInputElement;
let inputValue: string = String(get(settings)[settingContext][settingId]); let inputValue: string = String(get(settings)[settingContext][settingId]);
let inputFocused = false; let inputFocused = false;
let validInput = false;
let validInput: boolean;
const writeToSettings = (value: string, type: "url" | "uuid" | "text") => { const writeToSettings = (value: string, type: "url" | "uuid" | "text") => {
updateSetting({ updateSetting({
@ -59,7 +58,7 @@
</script> </script>
<div id="settings-input-holder"> <div id="settings-input-holder">
<div id="input-container" class:focused={inputFocused}> <div id="input-container" class:focused={inputFocused} aria-hidden="false">
<input <input
id="input-box" id="input-box"
bind:this={input} bind:this={input}
@ -73,16 +72,22 @@
autocapitalize="off" autocapitalize="off"
maxlength="64" maxlength="64"
pattern={regex[type]} pattern={regex[type]}
{placeholder} aria-label={altText}
aria-hidden="false"
/> />
{#if inputValue.length === 0}
<span class="input-placeholder" aria-hidden="true">
{placeholder}
</span>
{/if}
</div> </div>
<div id="settings-input-buttons"> <div id="settings-input-buttons">
<button <button
class="settings-input-button" class="settings-input-button"
aria-label={$t("button.save")} aria-label={$t("button.save")}
disabled={inputValue == $settings[settingContext][settingId] || disabled={inputValue == $settings[settingContext][settingId] || !validInput}
!validInput}
on:click={save} on:click={save}
> >
<IconCheck /> <IconCheck />
@ -114,6 +119,8 @@
display: flex; display: flex;
align-items: center; align-items: center;
width: 100%; width: 100%;
position: relative;
overflow: hidden;
} }
#input-container, #input-container,
@ -139,6 +146,13 @@
opacity: 1; opacity: 1;
} }
.input-placeholder {
position: absolute;
color: var(--gray);
pointer-events: none;
white-space: nowrap;
}
#input-box:focus-visible { #input-box:focus-visible {
box-shadow: unset !important; box-shadow: unset !important;
} }

View file

@ -24,6 +24,7 @@
settingId="customInstanceURL" settingId="customInstanceURL"
placeholder="https://instance.url.example/" placeholder="https://instance.url.example/"
showInstanceWarning showInstanceWarning
altText={$t("settings.processing.custom_instance.input.alt_text")}
/> />
{/if} {/if}
</div> </div>
@ -47,6 +48,7 @@
settingContext="processing" settingContext="processing"
settingId="customApiKey" settingId="customApiKey"
placeholder="00000000-0000-0000-0000-000000000000" placeholder="00000000-0000-0000-0000-000000000000"
altText={$t("settings.processing.access_key.input.alt_text")}
type="uuid" type="uuid"
/> />
{/if} {/if}