From f53ff4e5c4b0c2d54c7f74d677fb08519e499561 Mon Sep 17 00:00:00 2001
From: Sami Mazouz
Date: Fri, 10 Nov 2023 11:45:46 +0100
Subject: [PATCH] fix(a11y): convert empty links to buttons
---
extensions/tags/js/src/forum/addTagComposer.js | 8 ++++++--
extensions/tags/less/forum.less | 1 +
.../src/forum/components/DiscussionListItem.tsx | 12 +++++++++---
.../core/js/src/forum/components/LogInModal.tsx | 10 ++++++++--
.../core/js/src/forum/components/PostMeta.js | 5 +++--
.../js/src/forum/components/PostStreamScrubber.js | 13 +++++++------
.../core/js/src/forum/components/SignUpModal.tsx | 6 +++++-
framework/core/less/common/Button.less | 7 ++++++-
framework/core/less/common/mixins.less | 1 +
framework/core/less/common/mixins/typography.less | 9 +++++++++
framework/core/less/common/scaffolding.less | 8 +-------
framework/core/less/forum/Post.less | 2 +-
framework/core/less/forum/Scrubber.less | 15 +++------------
13 files changed, 60 insertions(+), 37 deletions(-)
create mode 100644 framework/core/less/common/mixins/typography.less
diff --git a/extensions/tags/js/src/forum/addTagComposer.js b/extensions/tags/js/src/forum/addTagComposer.js
index 7cffe7ce16..2af418e0b5 100644
--- a/extensions/tags/js/src/forum/addTagComposer.js
+++ b/extensions/tags/js/src/forum/addTagComposer.js
@@ -5,6 +5,7 @@ import classList from 'flarum/common/utils/classList';
import tagsLabel from '../common/helpers/tagsLabel';
import getSelectableTags from './utils/getSelectableTags';
+import Button from '@flarum/core/src/common/components/Button';
export default function addTagComposer() {
extend(IndexSidebar.prototype, 'newDiscussionAction', function (promise) {
@@ -47,13 +48,16 @@ export default function addTagComposer() {
items.add(
'tags',
-
+
{tags.length ? (
tagsLabel(tags)
) : (
{app.translator.trans('flarum-tags.forum.composer_discussion.choose_tags_link')}
)}
- ,
+ ,
10
);
});
diff --git a/extensions/tags/less/forum.less b/extensions/tags/less/forum.less
index bca726db6b..15798ee4b5 100644
--- a/extensions/tags/less/forum.less
+++ b/extensions/tags/less/forum.less
@@ -32,6 +32,7 @@
}
.DiscussionComposer-changeTags {
margin-right: 15px;
+ line-height: inherit;
&.disabled {
opacity: 0.5;
diff --git a/framework/core/js/src/forum/components/DiscussionListItem.tsx b/framework/core/js/src/forum/components/DiscussionListItem.tsx
index fd5decba8e..6dd785b9aa 100644
--- a/framework/core/js/src/forum/components/DiscussionListItem.tsx
+++ b/framework/core/js/src/forum/components/DiscussionListItem.tsx
@@ -148,9 +148,15 @@ export default class DiscussionListItem
-
-
-
+ {user ? (
+
+
+
+ ) : (
+
+
+
+ )}
,
100
);
diff --git a/framework/core/js/src/forum/components/LogInModal.tsx b/framework/core/js/src/forum/components/LogInModal.tsx
index c087e64310..f9b12182a8 100644
--- a/framework/core/js/src/forum/components/LogInModal.tsx
+++ b/framework/core/js/src/forum/components/LogInModal.tsx
@@ -122,10 +122,16 @@ export default class LogInModal
- {app.translator.trans('core.forum.log_in.forgot_password_link')}
+
+ {app.translator.trans('core.forum.log_in.forgot_password_link')}
+
{app.forum.attribute('allowSignUp') && (
- {app.translator.trans('core.forum.log_in.sign_up_text', { a: })}
+
+ {app.translator.trans('core.forum.log_in.sign_up_text', {
+ a: ,
+ })}
+
)}
>
);
diff --git a/framework/core/js/src/forum/components/PostMeta.js b/framework/core/js/src/forum/components/PostMeta.js
index 78573db5bf..892f54fcd1 100644
--- a/framework/core/js/src/forum/components/PostMeta.js
+++ b/framework/core/js/src/forum/components/PostMeta.js
@@ -2,6 +2,7 @@ import app from '../../forum/app';
import Component from '../../common/Component';
import humanTime from '../../common/helpers/humanTime';
import fullTime from '../../common/helpers/fullTime';
+import Button from '../../common/components/Button';
/**
* The `PostMeta` component displays the time of a post, and when clicked, shows
@@ -29,9 +30,9 @@ export default class PostMeta extends Component {
return (
-
+
{humanTime(time)}
-
+
{app.translator.trans('core.forum.post.number_tooltip', { number: post.number() })} {' '}
diff --git a/framework/core/js/src/forum/components/PostStreamScrubber.js b/framework/core/js/src/forum/components/PostStreamScrubber.js
index 6880bc9abc..a169497864 100644
--- a/framework/core/js/src/forum/components/PostStreamScrubber.js
+++ b/framework/core/js/src/forum/components/PostStreamScrubber.js
@@ -3,6 +3,7 @@ import Component from '../../common/Component';
import formatNumber from '../../common/utils/formatNumber';
import ScrollListener from '../../common/utils/ScrollListener';
import Icon from '../../common/components/Icon';
+import Button from '../../common/components/Button';
/**
* The `PostStreamScrubber` component displays a scrubber which can be used to
@@ -63,9 +64,9 @@ export default class PostStreamScrubber extends Component {
diff --git a/framework/core/js/src/forum/components/SignUpModal.tsx b/framework/core/js/src/forum/components/SignUpModal.tsx
index c456cbb7f4..ad74e5929d 100644
--- a/framework/core/js/src/forum/components/SignUpModal.tsx
+++ b/framework/core/js/src/forum/components/SignUpModal.tsx
@@ -137,7 +137,11 @@ export default class SignUpModal{app.translator.trans('core.forum.sign_up.log_in_text', { a: })}
,
+
+ {app.translator.trans('core.forum.sign_up.log_in_text', {
+ a: ,
+ })}
+
,
];
}
diff --git a/framework/core/less/common/Button.less b/framework/core/less/common/Button.less
index f6b829d9a0..fe31473a48 100644
--- a/framework/core/less/common/Button.less
+++ b/framework/core/less/common/Button.less
@@ -146,8 +146,9 @@
.Button--text {
background: transparent !important;
padding: 0;
- color: inherit !important;
+ --button-color: inherit;
line-height: inherit;
+ vertical-align: baseline;
&:hover {
text-decoration: underline;
@@ -158,6 +159,10 @@
box-shadow: none;
}
}
+.Button--link.Button--text {
+ .text-link();
+ --button-color: currentColor;
+}
.Button--primary {
.Button--color-auto('button-primary');
font-weight: bold;
diff --git a/framework/core/less/common/mixins.less b/framework/core/less/common/mixins.less
index 7a778a82e0..b23bea6753 100644
--- a/framework/core/less/common/mixins.less
+++ b/framework/core/less/common/mixins.less
@@ -5,3 +5,4 @@
@import "mixins/light-contents.less";
@import "mixins/header-background.less";
@import "mixins/vendor-prefixes.less";
+@import "mixins/typography.less";
diff --git a/framework/core/less/common/mixins/typography.less b/framework/core/less/common/mixins/typography.less
new file mode 100644
index 0000000000..85f86e583c
--- /dev/null
+++ b/framework/core/less/common/mixins/typography.less
@@ -0,0 +1,9 @@
+.text-link() {
+ cursor: pointer;
+ color: var(--link-color);
+ text-decoration: none;
+
+ &:hover {
+ text-decoration: underline;
+ }
+}
diff --git a/framework/core/less/common/scaffolding.less b/framework/core/less/common/scaffolding.less
index 732e291869..b64ddb0770 100644
--- a/framework/core/less/common/scaffolding.less
+++ b/framework/core/less/common/scaffolding.less
@@ -37,13 +37,7 @@ textarea {
}
a {
- cursor: pointer;
- color: var(--link-color);
- text-decoration: none;
-
- &:hover {
- text-decoration: underline;
- }
+ .text-link();
}
hr {
diff --git a/framework/core/less/forum/Post.less b/framework/core/less/forum/Post.less
index 264a1f3a98..5881129975 100644
--- a/framework/core/less/forum/Post.less
+++ b/framework/core/less/forum/Post.less
@@ -18,7 +18,7 @@
.Post-header {
margin-bottom: 15px;
- &, a {
+ &, a, .Button--text.Button--link {
color: var(--muted-color);
}
> ul {
diff --git a/framework/core/less/forum/Scrubber.less b/framework/core/less/forum/Scrubber.less
index 450229eed7..53e00e34bc 100644
--- a/framework/core/less/forum/Scrubber.less
+++ b/framework/core/less/forum/Scrubber.less
@@ -1,16 +1,7 @@
.Scrubber {
- & a {
- margin-left: -1px;
- color: var(--muted-color);
-
- & .fa {
- font-size: 14px;
- margin-right: 2px;
- }
- &:hover, &:focus {
- text-decoration: none;
- color: var(--link-color);
- }
+ &-first, &-last {
+ width: auto !important;
+ padding: 0;
}
}
.Scrubber-scrollbar {