Skip to content

Commit

Permalink
Update front end accessibility
Browse files Browse the repository at this point in the history
  • Loading branch information
theimbender committed Sep 26, 2023
1 parent f968ea5 commit fe35753
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 193 deletions.
173 changes: 85 additions & 88 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
{
"devDependencies": {
"@babel/core": "^7.22.17",
"@babel/preset-env": "^7.22.15",
"@babel/core": "^7.22.20",
"@babel/preset-env": "^7.22.20",
"@symfony/webpack-encore": "^4.4.0",
"bootstrap": "^5.3.1",
"bootstrap": "^5.3.2",
"date-fns": "^2.30.0",
"eslint-webpack-plugin": "^4.0.1",
"husky": "^8.0.3",
"lint-staged": "^14.0.1",
"prettier": "3.0.3",
"prettier": "^3.0.3",
"purgecss-webpack-plugin": "^5.0.0",
"sass": "^1.66.1",
"sass": "^1.68.0",
"sass-loader": "^13.3.2",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4"
},
"license": "MIT",
"private": true,
"engines": {
"npm": ">=7.0"
},
"scripts": {
"prepare": "husky install",
"dev-server": "encore dev-server",
Expand Down
45 changes: 1 addition & 44 deletions views/assets/css/style.scss
Original file line number Diff line number Diff line change
@@ -1,48 +1,5 @@
// Imports all of Bootstrap
// @import '~bootstrap/scss/bootstrap';

// Imports only used Bootstrap
@import "~bootstrap/scss/functions";
@import "~bootstrap/scss/variables";
@import "~bootstrap/scss/variables-dark";
@import "~bootstrap/scss/maps";
@import "~bootstrap/scss/mixins";
@import "~bootstrap/scss/root";
@import "~bootstrap/scss/reboot";
@import "~bootstrap/scss/type";
@import "~bootstrap/scss/utilities";
@import "~bootstrap/scss/utilities/api";
@import "~bootstrap/scss/helpers/visually-hidden";
// @import "~bootstrap/scss/images";
// @import "~bootstrap/scss/code";
@import "~bootstrap/scss/grid";
@import "~bootstrap/scss/containers";
// @import "~bootstrap/scss/tables";
@import "~bootstrap/scss/forms";
@import "~bootstrap/scss/buttons";
@import "~bootstrap/scss/transitions";
// @import "~bootstrap/scss/dropdown";
// @import "~bootstrap/scss/button-group";
@import "~bootstrap/scss/forms/input-group";
@import "~bootstrap/scss/forms/form-select";
// @import "~bootstrap/scss/custom-forms";
// @import "~bootstrap/scss/nav";
// @import "~bootstrap/scss/navbar";
@import "~bootstrap/scss/card";
// @import "~bootstrap/scss/breadcrumb";
// @import "~bootstrap/scss/pagination";
@import "~bootstrap/scss/badge";
// @import "~bootstrap/scss/jumbotron";
// @import "~bootstrap/scss/alert";
// @import "~bootstrap/scss/progress";
// @import "~bootstrap/scss/media";
// @import "~bootstrap/scss/list-group";
// @import "~bootstrap/scss/close";
// @import "~bootstrap/scss/modal";
@import "~bootstrap/scss/tooltip";
// @import "~bootstrap/scss/popover";
// @import "~bootstrap/scss/carousel";
// @import "~bootstrap/scss/print";
@import "~bootstrap/scss/bootstrap";

pre.file {
border-left: 2px solid $primary;
Expand Down
109 changes: 73 additions & 36 deletions views/assets/js/App/Collapse.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,106 @@
class Collapse {
constructor() {
this.toggleElements = Array.prototype.slice.call(
document.querySelectorAll('[data-toggle="collapse"]'),
);
this.collapsibleElements = Array.prototype.slice.call(
document.querySelectorAll(".collapse"),
const controls = Array.prototype.slice.call(
document.querySelectorAll("[aria-expanded][aria-controls]"),
);
this.collapsibleElements = controls.map((control) => [
control,
document.getElementById(control.getAttribute("aria-controls")),
]);
this.handleClick = this.handleClick.bind(this);
this.init();
}
handleClick(event) {
const targetId =
event.target.dataset.target || event.target.getAttribute("href");
const targetElement = document.querySelector(targetId);
if (!targetElement) {

handleClick({ target: control }) {
const container = document.getElementById(
control.getAttribute("aria-controls"),
);
if (!container) {
return false;
}

// Collapse this element
if (targetElement.getAttribute("aria-expanded") === "true") {
targetElement.setAttribute("aria-expanded", "false");
targetElement.style.maxHeight = 0;
if (control.getAttribute("aria-expanded") === "true") {
control.setAttribute("aria-expanded", "false");
container.style.maxHeight = 0;
return true;
}

// Expand this element
const naturalHeight = parseInt(targetElement.dataset.naturalHeight);
const naturalHeight = parseInt(container.dataset.naturalHeight);
if (isNaN(naturalHeight) || !naturalHeight) {
return false;
}
targetElement.setAttribute("aria-expanded", "true");
targetElement.style.maxHeight = naturalHeight + "px";
control.setAttribute("aria-expanded", "true");
container.hidden = false;

// Need to use requestAnimationFrame to force the browser to repaint after
// making the container visible, or it will skip the max-height transition
window.requestAnimationFrame(function () {
container.style.maxHeight = naturalHeight + "px";
});

return true;
}

handleTransitionEnd({ propertyName, target: container }) {
if (propertyName === "max-height") {
container.hidden = parseInt(container.style.maxHeight) === 0;
}
}

init() {
var instance = this;
const instance = this;

// Handle click events on the elements that toggle
this.toggleElements.forEach(function (element) {
element.addEventListener("click", function (event) {
this.collapsibleElements.forEach(function ([control, container]) {
// Handle click events on the elements that toggle
control.addEventListener("click", function (event) {
if (instance.handleClick(event)) {
event.preventDefault();
}
});
});

// Keep track of the natural heights of the collapsed elements
this.collapsibleElements.forEach(function (element) {
const initiallyVisible = element.classList.contains("show");
element.classList.add("show");

const naturalHeight = element.getBoundingClientRect().height;
element.dataset.naturalHeight = naturalHeight;
element.style.overflow = "hidden";
element.style.maxHeight = initiallyVisible
? naturalHeight + "px"
: 0;
element.style.transition = "max-height 0.25s";
element.setAttribute(
"aria-expanded",
initiallyVisible ? "true" : "false",
// Keep track of the natural heights of the collapsed elements
container.addEventListener(
"transitionend",
instance.handleTransitionEnd,
);
instance.resetNaturalHeight(control, container);
});

// Resets container natural heights on window resize
let timer = null;
window.addEventListener("resize", function () {
window.clearTimeout(timer);
timer = window.setTimeout(function () {
instance.collapsibleElements.forEach(function ([
control,
container,
]) {
instance.resetNaturalHeight(control, container);
});
}, 50);
});
}

resetNaturalHeight(control, container) {
// Default to fully visible
container.style.transition = "";
container.style.maxHeight = "";
container.style.overflow = "";
container.hidden = false;

const initiallyVisible =
control.getAttribute("aria-expanded") === "true";
const naturalHeight = container.getBoundingClientRect().height;
container.dataset.naturalHeight = naturalHeight;

// Set container dimensions
container.style.overflow = "hidden";
container.style.maxHeight = initiallyVisible ? naturalHeight + "px" : 0;
container.style.transition = "max-height 0.25s";
container.hidden = !initiallyVisible;
}
}

export default Collapse;
2 changes: 1 addition & 1 deletion views/build/app.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion views/build/style.css

Large diffs are not rendered by default.

23 changes: 14 additions & 9 deletions views/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
placeholder="Filter packages"
autocomplete="off"
autofocus>
<select class="form-select filter-field">
<select class="form-select filter-field" aria-label="Filter by...">
<option value="all" selected disabled hidden>Filter by..</option>
<option value="all">All fields</option>
<optgroup label="Specific field...">
Expand All @@ -59,8 +59,8 @@
aria-pressed="false"
aria-label="Toggle settings"
title="Toggle settings"
data-toggle="collapse"
data-target=".settings"
aria-expanded="false"
aria-controls="package-filter-settings"
>
<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" role="img">
<path d="M11.998 7.66A4.339 4.339 0 007.661 12a4.342 4.342 0 004.337 4.34A4.33 4.33 0 0016.323 12a4.327 4.327 0 00-4.325-4.34zm8.697 6.833l-.782 1.883 1.395 2.739.184.362-1.933 1.933-3.173-1.498-1.883.773-.956 2.927-.122.388h-2.733l-1.183-3.303-1.883-.777-2.743 1.391-.362.181-1.933-1.932 1.497-3.174-.776-1.882-2.921-.954L0 13.425v-2.732L3.306 9.51l.775-1.88-1.39-2.745-.183-.36 1.93-1.93L7.615 4.09l1.88-.778.956-2.924.123-.388h2.732l1.183 3.307 1.879.778 2.744-1.392.365-.184 1.931 1.93-1.496 3.172.773 1.885 2.93.955.385.123v2.73l-3.305 1.189z"/>
Expand All @@ -69,7 +69,7 @@
</div>
</div>
</form>
<form class="my-3 card collapse settings" aria-expanded="false">
<form id="package-filter-settings" class="my-3 card settings">
<div class="card-body">
<div class="form-group">
<p class="h6">Default package &quot;filter by&quot; field:</p>
Expand Down Expand Up @@ -100,7 +100,7 @@
name="default-filter"
value="custom">
<label class="form-check-label" for="package-filter-custom">Use this field:</label>
<select class="custom-select ml-2 default-filter-field">
<select class="custom-select ml-2 default-filter-field" aria-label="Default filter field">
<option value="all" selected disabled hidden>Select field...</option>
<option value="name">Name</option>
{% for fieldName, label in fieldsToToggle %}
Expand Down Expand Up @@ -135,12 +135,17 @@
<div id="repo-help" class="my-3">
<p class="small">
This is a private Composer repository.
To use it, you have to <a title="Check how to add this repository to your project" data-toggle="collapse" href="#repo-config">add this repository</a> to your <code>composer.json</code> file.
To use it, you have to <a
title="Check how to add this repository to your project"
href="#repo-config"
aria-expanded="false"
aria-controls="repo-config"
>add this repository</a> to your <code>composer.json</code> file.
</p>

<div id="repo-config" class="my-3 card card-outline collapse" aria-expanded="false">
<div id="repo-config" class="my-3 card card-outline">
<div class="card-body">
<h5 class="card-title">Setting up this repository in your projects</h5>
<h2 class="card-title h5">Setting up this repository in your projects</h2>
<p>
Add this <a href="https://getcomposer.org/" title="Visit getcomposer.org">Composer</a>
repository to your project's <code>composer.json</code>
Expand Down Expand Up @@ -191,7 +196,7 @@
</script>
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<symbol id="octicon-link" viewBox="0 0 16 16">
<path d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path>
<path fill="currentColor" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path>
</symbol>
</svg>
</body>
Expand Down
12 changes: 6 additions & 6 deletions views/package.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
{% set col2_class = 'col-sm-9 col-md-10' %}

<div class="card {% if package.abandoned %}border-danger{% else %}border-primary{% endif %} mb-3">
<div id="{{ package.highest.name }}" class="card-header field-name filter-by {% if package.abandoned %}bg-danger{% else %}bg-primary{% endif %}">
<a href="#{{ package.highest.name }}" class="text-white">
<div id="{{ package.highest.name }}" class="card-header field-name filter-by {% if package.abandoned %}text-bg-danger{% else %}text-bg-primary{% endif %}">
<a href="#{{ package.highest.name }}" class="text-reset">
<svg class="octicon-link" width="16" height="16">
<use xlink:href="#octicon-link"></use>
</svg>
Expand Down Expand Up @@ -42,7 +42,7 @@
<dt class="{{ col1_class }} field-keywords">Keywords</dt>
<dd class="{{ col2_class }} field-keywords filter-by">
{% for keyword in package.highest.keywords|sort %}
<span class="badge bg-info">{{ keyword }}</span>
<span class="badge text-bg-info">{{ keyword }}</span>
{% endfor %}
</dd>
{% endif %}
Expand Down Expand Up @@ -96,11 +96,11 @@
{%- if package.highest.type == 'metapackage' -%}
{{ version.prettyVersion }}
{%- elseif version.distType -%}
<a class="badge rounded-pill bg-secondary text-light" href="{{ version.distUrl }}" title="dist-reference: {{ version.distReference }}{{ branch_alias }}">{{ version.prettyVersion }}</a>
<a class="badge rounded-pill text-bg-secondary" href="{{ version.distUrl }}" title="dist-reference: {{ version.distReference }}{{ branch_alias }}">{{ version.prettyVersion }}</a>
{%- elseif version.sourceUrl matches '#^https?:\/\/#' -%}
<a class="badge rounded-pill bg-secondary text-light" href="{{ version.sourceUrl }}" title="source-reference: {{ version.sourceReference }}{{ branch_alias }}">{{ version.prettyVersion }}</a>
<a class="badge rounded-pill text-bg-secondary" href="{{ version.sourceUrl }}" title="source-reference: {{ version.sourceReference }}{{ branch_alias }}">{{ version.prettyVersion }}</a>
{%- else -%}
<span class="badge rounded-pill bg-secondary text-light" title="source-reference: {{ version.sourceReference }}{{ branch_alias }}">{{ version.prettyVersion }}</span>
<span class="badge rounded-pill text-bg-secondary" title="source-reference: {{ version.sourceReference }}{{ branch_alias }}">{{ version.prettyVersion }}</span>
{%- endif -%}
{% endfor %}
</dd>
Expand Down

0 comments on commit fe35753

Please sign in to comment.