Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status icon accessibility #12306

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/base/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -4335,6 +4335,28 @@ protected function tableAttributeHtml(string $attribute): string

return '';

case 'status':
if ($this->getIsUnpublishedDraft()) {
$icon = Html::tag('span', '', [
'data' => ['icon' => 'draft'],
'class' => 'draft-icon',
'aria' => [
'hidden' => 'true',
],
]);
$label = Craft::t('app', 'Draft');
} else {
$status = $this->getStatus();
$statusDef = static::statuses()[$status] ?? null;
$icon = Html::tag('span', '', ['class' => ['status', $statusDef['color'] ?? $status]]);
$label = $statusDef['label'] ?? $statusDef ?? ucfirst($status);
}
return Html::beginTag('span', [
'class' => 'status-wrapper',
]) .
$icon . Html::tag('span', $label) .
Html::endTag('span');

case 'uri':
if ($this->getIsDraft() && ElementHelper::isTempSlug($this->slug)) {
return '';
Expand Down
2 changes: 2 additions & 0 deletions src/elements/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ protected static function defineTableAttributes(): array
'uid' => ['label' => Craft::t('app', 'UID')],
'dateCreated' => ['label' => Craft::t('app', 'Date Created')],
'dateUpdated' => ['label' => Craft::t('app', 'Date Updated')],
'status' => ['label' => Craft::t('app', 'Status')],
];
}

Expand All @@ -351,6 +352,7 @@ protected static function defineDefaultTableAttributes(string $source): array
{
return [
'link',
'status',
];
}

Expand Down
2 changes: 2 additions & 0 deletions src/elements/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ protected static function defineTableAttributes(): array
'type' => ['label' => Craft::t('app', 'Entry Type')],
'author' => ['label' => Craft::t('app', 'Author')],
'slug' => ['label' => Craft::t('app', 'Slug')],
'status' => ['label' => Craft::t('app', 'Status')],
'uri' => ['label' => Craft::t('app', 'URI')],
'postDate' => ['label' => Craft::t('app', 'Post Date')],
'expiryDate' => ['label' => Craft::t('app', 'Expiry Date')],
Expand Down Expand Up @@ -554,6 +555,7 @@ protected static function defineDefaultTableAttributes(string $source): array
}

$attributes[] = 'link';
$attributes[] = 'status';

return $attributes;
}
Expand Down
2 changes: 2 additions & 0 deletions src/elements/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ protected static function defineTableAttributes(): array
'lastLoginDate' => ['label' => Craft::t('app', 'Last Login')],
'dateCreated' => ['label' => Craft::t('app', 'Date Created')],
'dateUpdated' => ['label' => Craft::t('app', 'Date Updated')],
'status' => ['label' => Craft::t('app', 'Status')],
];
}

Expand All @@ -453,6 +454,7 @@ protected static function defineDefaultTableAttributes(string $source): array
'email',
'dateCreated',
'lastLoginDate',
'status',
];
}

Expand Down
19 changes: 14 additions & 5 deletions src/helpers/Cp.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ public static function elementHtml(

if ($context === 'field') {
$attributes['class'][] = 'removable';
} else {
$showStatus = false;
}

if ($element->hasErrors()) {
Expand Down Expand Up @@ -494,30 +496,37 @@ public static function elementHtml(
}

if ($showStatus) {
$innerHtml .= '<div class="element__status">';
if ($isDraft) {
$innerHtml .= Html::tag('span', '', [
'data' => ['icon' => 'draft'],
'class' => 'icon',
'role' => 'img',
'class' => ['icon', 'element__status-icon'],
'aria' => [
'label' => sprintf('%s %s', Craft::t('app', 'Status:'), Craft::t('app', 'Draft')),
'hidden' => 'true',
],
]) .
Html::tag('span', Craft::t('app', 'Draft'), [
'class' => ['element__status-text'],
]);
} else {
$status = $element->getStatus();
$statusDef = $element::statuses()[$status] ?? null;
$innerHtml .= Html::tag('span', '', [
'class' => array_filter([
'status',
'element__status-icon',
$status,
$statusDef['color'] ?? null,
]),
'role' => 'img',
'aria' => [
'label' => sprintf('%s %s', Craft::t('app', 'Status:'), $statusDef['label'] ?? $statusDef ?? ucfirst($status)),
'hidden' => 'true',
],
]) .
Html::tag('span', $statusDef['label'] ?? $statusDef ?? ucfirst($status), [
'class' => 'element__status-text',
]);
}
$innerHtml .= '</div>';
}

// Allow plugins to modify the inner HTML
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/css/cp.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/css/cp.css.map

Large diffs are not rendered by default.

82 changes: 52 additions & 30 deletions src/web/assets/cp/src/css/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
--inner-focus-ring: inset 0 0 0 1px hsl(var(--dark-focus-hsl)),
inset 0 0 0 3px hsla(var(--dark-focus-hsl), 0.7);
--touch-target-size: 24px; /* Minimum recommended touch target size */
--status-spacer: 10px;
}

body,
Expand Down Expand Up @@ -2476,20 +2477,24 @@ $elementInnerSpacing: 5px;
font-weight: normal;
border-radius: var(--small-border-radius);

.field & {
margin: 5px;
}

.field .row & {
margin: 0;
}

&:focus,
li:focus & {
background-color: var(--gray-050);
}

&.sel,
li.sel & {
background-color: var(--light-sel-color) !important;
background-color: var(--gray-050) !important;
cursor: default;

&:focus {
background-color: darken($lightSelColor, 5%) !important;
}

&.hasthumb {
.elementthumb {
img {
Expand Down Expand Up @@ -2555,21 +2560,8 @@ $elementInnerSpacing: 5px;
box-sizing: border-box;

&.hasstatus {
@include padding-left(
$baseElementSidePadding + $statusSize + $elementInnerSpacing
);

.status {
position: absolute;
@include left($baseElementSidePadding);
top: calc(50% - 5px);
}

.icon:not(.delete) {
position: absolute;
@include left($baseElementSidePadding - 1);
top: calc(50% - 11px);
}
border: 1px solid var(--hairline-color);
padding: var(--s) var(--m);
}

&.hasthumb {
Expand Down Expand Up @@ -2636,19 +2628,23 @@ $elementInnerSpacing: 5px;
}

&.removable {
.label {
@include padding-right(20px);
}
@include padding-right(60px);

.delete:before {
color: var(--ui-control-color);
line-height: inherit;
}

.delete {
@include touch-target();
}

&.small,
&.large:not(.hasthumb) {
.delete {
position: absolute;
top: calc(50% - 11px);
top: 50%;
transform: translateY(-50%);
@include right($baseElementSidePadding);
}
}
Expand All @@ -2668,6 +2664,17 @@ $elementInnerSpacing: 5px;
}
}

.element__status {
.element__status-icon {
@include margin-right(4px);
}

.element__status-text {
font-size: toRem(13);
color: var(--gray-500);
}
}

$checkboxPadding: $checkboxSize + 4;

.elements {
Expand Down Expand Up @@ -2814,6 +2821,13 @@ $checkboxPadding: $checkboxSize + 4;
}
}
}

// field view
.field & {
+ .flex {
margin-top: var(--s);
}
}
}

.export-form {
Expand Down Expand Up @@ -3017,10 +3031,6 @@ $checkboxPadding: $checkboxSize + 4;
}
}
}

.flex {
padding-top: 7px;
}
}

/* editable tables */
Expand Down Expand Up @@ -3270,11 +3280,24 @@ ul.tree,
@include margin(7px, 0, 0, -15px);
}

/* status wrapper */
.status-wrapper {
--status-spacer: 6px;
display: flex;
align-items: center;
}

/* status icons */
.draft-icon {
--status-spacer: 4px;
display: inline-flex;
@include margin-right(var(--status-spacer));
}

.status {
display: inline-block;
@include margin-right(var(--status-spacer));
position: relative;
@include margin-right(10px);
width: 10px;
height: 10px;
border: 1px solid transparent;
Expand Down Expand Up @@ -3984,7 +4007,6 @@ $min2ColWidth: 400px;

& > [data-icon='draft'] {
margin-top: -2px;
@include margin-right(8px);
}
}

Expand Down