fix(a11y): Change the look and behavior of some file upload fields

This commit is contained in:
Jay Sitter 2023-06-25 02:27:07 -04:00
parent a0857a5eb8
commit dc43c51b0d
5 changed files with 146 additions and 137 deletions

View file

@ -88,6 +88,15 @@
color: var(--bs-gray) !important;
}
input[type="file"]::file-selector-button {
font: inherit;
border: 0;
padding: 0.375em 0.75em;
border-radius: var(--bs-border-radius);
background-color: var(--bs-secondary);
color: var(--bs-white);
}
.icon {
display: inline-grid;
display: inline-flex;

View file

@ -33,8 +33,7 @@ export class ImageUploadForm extends Component<
render() {
return (
<form className="image-upload-form d-inline">
<label htmlFor={this.id} className="pointer text-muted small fw-bold">
{this.props.imageSrc ? (
{this.props.imageSrc && (
<span className="d-inline-block position-relative">
{/* TODO: Create "Current Iamge" translation for alt text */}
<img
@ -55,16 +54,13 @@ export class ImageUploadForm extends Component<
<Icon icon="x" classes="mini-overlay" />
</button>
</span>
) : (
<span className="btn btn-secondary">{this.props.uploadTitle}</span>
)}
</label>
<input
id={this.id}
type="file"
accept="image/*,video/*"
className="small"
name={this.id}
className="d-none"
disabled={!UserService.Instance.myUserInfo}
onChange={linkEvent(this, this.handleImageUpload)}
/>

View file

@ -87,7 +87,10 @@ export class EmojiForm extends Component<EmojiFormProps, EmojiFormState> {
</div>
)}
<div className="table-responsive">
<table id="emojis_table" className="table table-sm table-hover">
<table
id="emojis_table"
className="table table-sm table-hover align-middle"
>
<thead className="pointer">
<tr>
<th>{I18NextService.i18n.t("column_emoji")}</th>
@ -129,8 +132,9 @@ export class EmojiForm extends Component<EmojiFormProps, EmojiFormState> {
/>
)}
{cv.image_url.length === 0 && (
<form>
<label
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
tabIndex={0}
className="btn btn-sm btn-secondary pointer"
htmlFor={`file-uploader-${index}`}
data-tippy-content={I18NextService.i18n.t(
@ -152,7 +156,6 @@ export class EmojiForm extends Component<EmojiFormProps, EmojiFormState> {
)}
/>
</label>
</form>
)}
</td>
<td className="text-right">

View file

@ -155,10 +155,11 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
/>
</div>
</div>
<div className="input-group mb-3">
<label className="me-2 col-form-label">
<div className="row mb-3">
<label className="col-sm-2 col-form-label">
{I18NextService.i18n.t("icon")}
</label>
<div className="col-sm-10">
<ImageUploadForm
uploadTitle={I18NextService.i18n.t("upload_icon")}
imageSrc={this.state.siteForm.icon}
@ -167,10 +168,12 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
rounded
/>
</div>
<div className="input-group mb-3">
<label className="me-2 col-form-label">
</div>
<div className="row mb-3">
<label className="col-sm-2 col-form-label">
{I18NextService.i18n.t("banner")}
</label>
<div className="col-sm-10">
<ImageUploadForm
uploadTitle={I18NextService.i18n.t("upload_banner")}
imageSrc={this.state.siteForm.banner}
@ -178,6 +181,7 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
onRemove={this.handleBannerRemove}
/>
</div>
</div>
<div className="mb-3 row">
<label className="col-12 col-form-label" htmlFor="site-desc">
{I18NextService.i18n.t("description")}

View file

@ -347,32 +347,12 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
<input
type="url"
id="post-url"
className="form-control"
className="form-control mb-3"
value={url}
onInput={linkEvent(this, handlePostUrlChange)}
onPaste={linkEvent(this, handleImageUploadPaste)}
/>
{this.renderSuggestedTitleCopy()}
<form>
<label
htmlFor="file-upload"
className={`${
UserService.Instance.myUserInfo && "pointer"
} d-inline-block float-right text-muted fw-bold`}
data-tippy-content={I18NextService.i18n.t("upload_image")}
>
<Icon icon="image" classes="icon-inline" />
</label>
<input
id="file-upload"
type="file"
accept="image/*,video/*"
name="file"
className="d-none"
disabled={!UserService.Instance.myUserInfo}
onChange={linkEvent(this, handleImageUpload)}
/>
</form>
{url && validURL(url) && (
<div>
<a
@ -402,6 +382,23 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
</a>
</div>
)}
</div>
</div>
<div className="mb-3 row">
<label htmlFor="file-upload" className={"col-sm-2 col-form-label"}>
{capitalizeFirstLetter(I18NextService.i18n.t("image"))}
<Icon icon="image" classes="icon-inline ms-1" />
</label>
<input
id="file-upload"
type="file"
accept="image/*,video/*"
name="file"
className="small col-sm-10"
disabled={!UserService.Instance.myUserInfo}
onChange={linkEvent(this, handleImageUpload)}
/>
{this.state.imageLoading && <Spinner />}
{url && isImage(url) && (
<img src={url} className="img-fluid" alt="" />
@ -451,7 +448,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
</>
)}
</div>
</div>
<div className="mb-3 row">
<label className="col-sm-2 col-form-label" htmlFor="post-title">
{I18NextService.i18n.t("title")}