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

Replace Chosen with accessible-autocomplete #1161

Merged
merged 9 commits into from
Feb 1, 2021
Merged
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
5,296 changes: 2,576 additions & 2,720 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"node": ">=8.10.0"
},
"dependencies": {
"chosen-js": "^1.8.7",
"jquery": "^3.5.1",
"node-sass": "^4.14.1",
"uswds": "^2.10.0"
Expand Down
31 changes: 19 additions & 12 deletions tock/tock/static/js/components/timecard.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function populateHourTotals() {

function toggleNotesField(selectBox) {
var $fieldset = $(selectBox).parents('.entry-project'),
$selected = $(selectBox).find(':selected'),
$selected = $fieldset.find(':selected'),
$notes = $fieldset.find('.entry-note-field'),
notesDisplayed = $selected.data('notes-displayed'),
notesRequired = $selected.data('notes-required');
Expand All @@ -118,7 +118,7 @@ function toggleNotesField(selectBox) {

function displayAlerts(selectBox) {
var $fieldset = $(selectBox).parents('.entry-project'),
$selected = $(selectBox).find(':selected'),
$selected = $fieldset.find(':selected'),
$alerts = $fieldset.find('.entry-alerts'),
all_alerts = $selected.data('alerts'),
alert_text;
Expand Down Expand Up @@ -164,7 +164,6 @@ function addTockLines(tockLines) {
setTimeout(function () {
// Set the project and trigger a GUI update
$("div.entry:last .entry-project select").val(line.project);
$("div.entry:last .entry-project select").trigger("chosen:updated");

// Set the hours and trigger a data update
$("div.entry:last .entry-amount input").val(line.hours);
Expand Down Expand Up @@ -197,11 +196,6 @@ $("body").on("change", ".entry-project select", function () {


$(document).ready(function () {
var chosenOptions = {
search_contains: true,
group_search: false
};

$("#save-timecard").on("click", function () {
// Clear anything saved locally. The server is the
// source of truth.
Expand All @@ -225,7 +219,7 @@ $(document).ready(function () {
$(".add-timecard-entry").on("click", function () {
$('div.entry:last').clone().each(function (i) {
var entry = $(this);
entry.find('.chosen-container').remove();
entry.find('.autocomplete__wrapper').remove();
entry.find('.entry-alerts').empty();
entry.find('.entry-note-field').toggleClass('entry-hidden', true);
entry.find('.entry-note-field .invalid').remove();
Expand Down Expand Up @@ -262,8 +256,13 @@ $(document).ready(function () {
});
}).appendTo('.entries');

accessibleAutocomplete.enhanceSelectElement({
showAllValues: true,
defaultValue: '',
selectElement: document.querySelector('div.entry:last-child .entry-project select')
});

$('div.entry:last').find('.entry-project select')
.chosen(chosenOptions)
.on('change', function (e) {
toggleNotesField(this);
displayAlerts(this);
Expand Down Expand Up @@ -304,8 +303,16 @@ $(document).ready(function () {
// Run on initial load
populateHourTotals();

$('.entry-project select')
.chosen(chosenOptions)
const selects = document.querySelectorAll('.entry-project select');
selects.forEach(select => {
accessibleAutocomplete.enhanceSelectElement({
showAllValues: true,
defaultValue: '',
selectElement: select
})
});

$('.entry-project input')
.on('change', function (e) {
toggleNotesField(this);
displayAlerts(this);
Expand Down
14 changes: 11 additions & 3 deletions tock/tock/static/sass/_entries.scss
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,17 @@
}
}

/*.entry-project {
@include span-columns(6);
}*/
.entry-project {
.autocomplete__dropdown-arrow-down {
z-index: 1; //override to accessible-autocomplete's -1 index, which hides arrow
top: 18px; //override to accommodate extra margin on input
}
.autocomplete__hint, .autocomplete__input {
border: 1px solid #565c65;
color: #1b1b1b;
margin-top: 0.5rem;
}
}

.entry-notes {
textarea {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Binary file removed tock/tock/static/vendor/chosen_v1.8.7/chosen-sprite.png
Binary file not shown.
Binary file not shown.
3 changes: 0 additions & 3 deletions tock/tock/static/vendor/chosen_v1.8.7/chosen.jquery.min.js

This file was deleted.

11 changes: 0 additions & 11 deletions tock/tock/static/vendor/chosen_v1.8.7/chosen.min.css

This file was deleted.

4 changes: 2 additions & 2 deletions tock/tock/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
<meta name="tock-icon-angry" content="{% static 'img/favicon-angry' %}">
<link rel="stylesheet" href="{% static 'css/dist/core.css' %}">
<link rel="stylesheet" href="{% static 'vendor/jqueryui_v1.12.1/jquery-ui.min.css' %}">
<link rel="stylesheet" href="{% static 'vendor/chosen_v1.8.7/chosen.min.css' %}">
<link rel="stylesheet" href="{% static 'css/vendor/font-awesome.min.css' %}">
<link rel="stylesheet" href="{% static 'vendor/accessible-autocomplete_v2.0.3/css/accessible-autocomplete.min.css' %}" />
<script src="{% static 'vendor/jquery_v3.5.1/jquery.min.js' %}"></script>
<script src="{% static 'vendor/chosen_v1.8.7/chosen.jquery.min.js' %}"></script>
<script src="{% static 'vendor/jqueryui_v1.12.1/jquery-ui.min.js' %}"></script>
<script src="{% static 'vendor/uswds_v2.3.1/js/uswds.min.js' %}"></script>
<script type="text/javascript" src="{% static 'vendor/accessible-autocomplete_v2.0.3/js/accessible-autocomplete.min.js' %}"></script>

<script src="{% static 'js/components/notifications.js' %}"></script>
<script>
Expand Down