fix(a11y): Change the look and behavior of some file upload fields
authorJay Sitter <jay@jaysitter.com>
Sun, 25 Jun 2023 06:27:07 +0000 (02:27 -0400)
committerJay Sitter <jay@jaysitter.com>
Sun, 25 Jun 2023 06:27:07 +0000 (02:27 -0400)
src/assets/css/main.css
src/shared/components/common/image-upload-form.tsx
src/shared/components/home/emojis-form.tsx
src/shared/components/home/site-form.tsx
src/shared/components/post/post-form.tsx

index cb4a8b818abb27e4b5015336a41ec0ec90847193..dde2a503ad866f69d37d40dce47e9f745fe86c02 100644 (file)
   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;
index e8005ccc8d4bc04d216b4c6b428acc618bf9b4e0..107949f6acb9187e01a14dcfe8f654405cb2f6c1 100644 (file)
@@ -33,38 +33,34 @@ 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 ? (
-            <span className="d-inline-block position-relative">
-              {/* TODO: Create "Current Iamge" translation for alt text */}
-              <img
-                alt=""
-                src={this.props.imageSrc}
-                height={this.props.rounded ? 60 : ""}
-                width={this.props.rounded ? 60 : ""}
-                className={`img-fluid ${
-                  this.props.rounded ? "rounded-circle" : ""
-                }`}
-              />
-              <button
-                className="position-absolute d-block p-0 end-0 border-0 top-0 bg-transparent text-white"
-                type="button"
-                onClick={linkEvent(this, this.handleRemoveImage)}
-                aria-label={I18NextService.i18n.t("remove")}
-              >
-                <Icon icon="x" classes="mini-overlay" />
-              </button>
-            </span>
-          ) : (
-            <span className="btn btn-secondary">{this.props.uploadTitle}</span>
-          )}
-        </label>
+        {this.props.imageSrc && (
+          <span className="d-inline-block position-relative">
+            {/* TODO: Create "Current Iamge" translation for alt text */}
+            <img
+              alt=""
+              src={this.props.imageSrc}
+              height={this.props.rounded ? 60 : ""}
+              width={this.props.rounded ? 60 : ""}
+              className={`img-fluid ${
+                this.props.rounded ? "rounded-circle" : ""
+              }`}
+            />
+            <button
+              className="position-absolute d-block p-0 end-0 border-0 top-0 bg-transparent text-white"
+              type="button"
+              onClick={linkEvent(this, this.handleRemoveImage)}
+              aria-label={I18NextService.i18n.t("remove")}
+            >
+              <Icon icon="x" classes="mini-overlay" />
+            </button>
+          </span>
+        )}
         <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)}
         />
index caf8221c7569713aa7b3c60b1a04ca90ab137ec5..930bd55c5bcfd7ff3b26743ed8ba523faba06746 100644 (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,30 +132,30 @@ export class EmojiForm extends Component<EmojiFormProps, EmojiFormState> {
                         />
                       )}
                       {cv.image_url.length === 0 && (
-                        <form>
-                          <label
-                            className="btn btn-sm btn-secondary pointer"
-                            htmlFor={`file-uploader-${index}`}
-                            data-tippy-content={I18NextService.i18n.t(
-                              "upload_image"
-                            )}
-                          >
-                            {capitalizeFirstLetter(
-                              I18NextService.i18n.t("upload")
+                        <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(
+                            "upload_image"
+                          )}
+                        >
+                          {capitalizeFirstLetter(
+                            I18NextService.i18n.t("upload")
+                          )}
+                          <input
+                            name={`file-uploader-${index}`}
+                            id={`file-uploader-${index}`}
+                            type="file"
+                            accept="image/*"
+                            className="d-none"
+                            onChange={linkEvent(
+                              { form: this, index: index },
+                              this.handleImageUpload
                             )}
-                            <input
-                              name={`file-uploader-${index}`}
-                              id={`file-uploader-${index}`}
-                              type="file"
-                              accept="image/*"
-                              className="d-none"
-                              onChange={linkEvent(
-                                { form: this, index: index },
-                                this.handleImageUpload
-                              )}
-                            />
-                          </label>
-                        </form>
+                          />
+                        </label>
                       )}
                     </td>
                     <td className="text-right">
index 382f565098ee01a56d77b8cf1839ffc51c352339..e30d13bf34ac5deb8b06fa0c078e0d1bffef4334 100644 (file)
@@ -155,28 +155,32 @@ 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>
-          <ImageUploadForm
-            uploadTitle={I18NextService.i18n.t("upload_icon")}
-            imageSrc={this.state.siteForm.icon}
-            onUpload={this.handleIconUpload}
-            onRemove={this.handleIconRemove}
-            rounded
-          />
+          <div className="col-sm-10">
+            <ImageUploadForm
+              uploadTitle={I18NextService.i18n.t("upload_icon")}
+              imageSrc={this.state.siteForm.icon}
+              onUpload={this.handleIconUpload}
+              onRemove={this.handleIconRemove}
+              rounded
+            />
+          </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("banner")}
           </label>
-          <ImageUploadForm
-            uploadTitle={I18NextService.i18n.t("upload_banner")}
-            imageSrc={this.state.siteForm.banner}
-            onUpload={this.handleBannerUpload}
-            onRemove={this.handleBannerRemove}
-          />
+          <div className="col-sm-10">
+            <ImageUploadForm
+              uploadTitle={I18NextService.i18n.t("upload_banner")}
+              imageSrc={this.state.siteForm.banner}
+              onUpload={this.handleBannerUpload}
+              onRemove={this.handleBannerRemove}
+            />
+          </div>
         </div>
         <div className="mb-3 row">
           <label className="col-12 col-form-label" htmlFor="site-desc">
index 081792aa0e35841df6cefbe79728d653946621a4..b71ef5477e0b28bb59ea862b3c23963dcd64f8ca 100644 (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,56 +382,73 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
                 </a>
               </div>
             )}
-            {this.state.imageLoading && <Spinner />}
-            {url && isImage(url) && (
-              <img src={url} className="img-fluid" alt="" />
-            )}
-            {this.state.imageDeleteUrl && (
-              <button
-                className="btn btn-danger btn-sm mt-2"
-                onClick={linkEvent(this, handleImageDelete)}
-                aria-label={I18NextService.i18n.t("delete")}
-                data-tippy-content={I18NextService.i18n.t("delete")}
-              >
-                <Icon icon="x" classes="icon-inline me-1" />
-                {capitalizeFirstLetter(I18NextService.i18n.t("delete"))}
-              </button>
-            )}
-            {this.props.crossPosts && this.props.crossPosts.length > 0 && (
-              <>
-                <div className="my-1 text-muted small fw-bold">
-                  {I18NextService.i18n.t("cross_posts")}
-                </div>
-                <PostListings
-                  showCommunity
-                  posts={this.props.crossPosts}
-                  enableDownvotes={this.props.enableDownvotes}
-                  enableNsfw={this.props.enableNsfw}
-                  allLanguages={this.props.allLanguages}
-                  siteLanguages={this.props.siteLanguages}
-                  viewOnly
-                  // All of these are unused, since its view only
-                  onPostEdit={() => {}}
-                  onPostVote={() => {}}
-                  onPostReport={() => {}}
-                  onBlockPerson={() => {}}
-                  onLockPost={() => {}}
-                  onDeletePost={() => {}}
-                  onRemovePost={() => {}}
-                  onSavePost={() => {}}
-                  onFeaturePost={() => {}}
-                  onPurgePerson={() => {}}
-                  onPurgePost={() => {}}
-                  onBanPersonFromCommunity={() => {}}
-                  onBanPerson={() => {}}
-                  onAddModToCommunity={() => {}}
-                  onAddAdmin={() => {}}
-                  onTransferCommunity={() => {}}
-                />
-              </>
-            )}
           </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="" />
+          )}
+          {this.state.imageDeleteUrl && (
+            <button
+              className="btn btn-danger btn-sm mt-2"
+              onClick={linkEvent(this, handleImageDelete)}
+              aria-label={I18NextService.i18n.t("delete")}
+              data-tippy-content={I18NextService.i18n.t("delete")}
+            >
+              <Icon icon="x" classes="icon-inline me-1" />
+              {capitalizeFirstLetter(I18NextService.i18n.t("delete"))}
+            </button>
+          )}
+          {this.props.crossPosts && this.props.crossPosts.length > 0 && (
+            <>
+              <div className="my-1 text-muted small fw-bold">
+                {I18NextService.i18n.t("cross_posts")}
+              </div>
+              <PostListings
+                showCommunity
+                posts={this.props.crossPosts}
+                enableDownvotes={this.props.enableDownvotes}
+                enableNsfw={this.props.enableNsfw}
+                allLanguages={this.props.allLanguages}
+                siteLanguages={this.props.siteLanguages}
+                viewOnly
+                // All of these are unused, since its view only
+                onPostEdit={() => {}}
+                onPostVote={() => {}}
+                onPostReport={() => {}}
+                onBlockPerson={() => {}}
+                onLockPost={() => {}}
+                onDeletePost={() => {}}
+                onRemovePost={() => {}}
+                onSavePost={() => {}}
+                onFeaturePost={() => {}}
+                onPurgePerson={() => {}}
+                onPurgePost={() => {}}
+                onBanPersonFromCommunity={() => {}}
+                onBanPerson={() => {}}
+                onAddModToCommunity={() => {}}
+                onAddAdmin={() => {}}
+                onTransferCommunity={() => {}}
+              />
+            </>
+          )}
+        </div>
+
         <div className="mb-3 row">
           <label className="col-sm-2 col-form-label" htmlFor="post-title">
             {I18NextService.i18n.t("title")}