Skip to content

Commit

Permalink
[5.0.x] Fixed #34995 -- Improved position of related widget's add lin…
Browse files Browse the repository at this point in the history
…k on admin pages on small screens.

Regression in 1699f8b.

Co-authored-by: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com>
Co-authored-by: Natalia Bidart <124304+nessita@users.noreply.github.com>

Backport of 999ba9d from main
  • Loading branch information
knyghty authored and nessita committed Nov 30, 2023
1 parent 9fe12b0 commit 471fa92
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 45 deletions.
31 changes: 1 addition & 30 deletions django/contrib/admin/static/admin/css/responsive.css
Original file line number Diff line number Diff line change
Expand Up @@ -237,22 +237,6 @@ input[type="submit"], button {
padding: 7px;
}

/* Related widget */

.related-widget-wrapper {
float: none;
}

.related-widget-wrapper-link + .selector {
max-width: calc(100% - 30px);
margin-right: 15px;
}

select + .related-widget-wrapper-link,
.related-widget-wrapper-link + .related-widget-wrapper-link {
margin-left: 10px;
}

/* Selector */

.selector {
Expand All @@ -270,7 +254,7 @@ input[type="submit"], button {
}

.selector .selector-filter input {
width: auto;
width: 100%;
min-height: 0;
flex: 1 1;
}
Expand All @@ -292,7 +276,6 @@ input[type="submit"], button {
width: 26px;
height: 52px;
padding: 2px 0;
margin: auto 15px;
border-radius: 20px;
transform: translateY(-10px);
}
Expand Down Expand Up @@ -336,7 +319,6 @@ input[type="submit"], button {
width: 52px;
height: 26px;
padding: 0 2px;
margin: 15px auto;
transform: none;
}

Expand Down Expand Up @@ -684,21 +666,12 @@ input[type="submit"], button {
align-self: center;
}

select + .related-widget-wrapper-link,
.related-widget-wrapper-link + .related-widget-wrapper-link {
margin-left: 15px;
}

/* Selector */

.selector {
flex-direction: column;
}

.selector > * {
float: none;
}

.selector-available, .selector-chosen {
margin-bottom: 0;
flex: 1 1 auto;
Expand All @@ -710,11 +683,9 @@ input[type="submit"], button {

.selector ul.selector-chooser {
display: block;
float: none;
width: 52px;
height: 26px;
padding: 0 2px;
margin: 15px auto 20px;
transform: none;
}

Expand Down
4 changes: 4 additions & 0 deletions django/contrib/admin/static/admin/css/rtl.css
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,7 @@ form .form-row p.datetime {
margin-left: inherit;
margin-right: 2px;
}

.selector .selector-chooser {
margin: 0;
}
26 changes: 13 additions & 13 deletions django/contrib/admin/static/admin/css/widgets.css
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
/* SELECTOR (FILTER INTERFACE) */

.selector {
width: 800px;
float: left;
display: flex;
flex-grow: 1;
gap: 10px;
}

.selector select {
width: 380px;
height: 17.2em;
flex: 1 0 auto;
overflow: scroll;
width: 100%;
}

.selector-available, .selector-chosen {
width: 380px;
text-align: center;
margin-bottom: 5px;
display: flex;
flex-direction: column;
flex: 1 1;
}

.selector-available h2, .selector-chosen h2 {
Expand Down Expand Up @@ -58,6 +59,7 @@
font-size: 0.625rem;
margin: 0;
text-align: left;
display: flex;
}

.selector .selector-filter label,
Expand All @@ -72,9 +74,12 @@
min-width: auto;
}

.selector-filter input {
flex-grow: 1;
}

.selector .selector-available input,
.selector .selector-chosen input {
width: 320px;
margin-left: 8px;
}

Expand All @@ -83,7 +88,6 @@
width: 22px;
background-color: var(--selected-bg);
border-radius: 10px;
margin: 0 5px;
padding: 0;
transform: translateY(-17px);
}
Expand Down Expand Up @@ -575,8 +579,9 @@ ul.timelist, .timelist li {

/* RELATED WIDGET WRAPPER */
.related-widget-wrapper {
float: left; /* display properly in form rows with multiple fields */
overflow: hidden; /* clear floated contents */
display: flex;
gap: 10px;
flex-grow: 1;
}

.related-widget-wrapper-link {
Expand All @@ -589,11 +594,6 @@ ul.timelist, .timelist li {
filter: grayscale(0);
}

select + .related-widget-wrapper-link,
.related-widget-wrapper-link + .related-widget-wrapper-link {
margin-left: 7px;
}

/* GIS MAPS */
.dj_map {
width: 600px;
Expand Down
3 changes: 3 additions & 0 deletions django/contrib/admin/static/admin/js/SelectFilter2.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ Requires core.js and SelectBox.js.

// <div class="selector"> or <div class="selector stacked">
const selector_div = quickElement('div', from_box.parentNode);
// Make sure the selector div is at the beginning so that the
// add link would be displayed to the right of the widget.
from_box.parentNode.prepend(selector_div);
selector_div.className = is_stacked ? 'selector stacked' : 'selector';

// <div class="selector-available">
Expand Down
8 changes: 6 additions & 2 deletions js_tests/admin/SelectFilter2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ QUnit.module('admin.SelectFilter2');

QUnit.test('init', function(assert) {
const $ = django.jQuery;
$('<form><select id="id"></select></form>').appendTo('#qunit-fixture');
$('<option value="0">A</option>').appendTo('#id');
$('<form id="test"></form>').appendTo('#qunit-fixture');
$('<label for="id_id">Test</label>').appendTo('#test');
$('<div class="helptext">This is helpful.</div>').appendTo('#test');
$('<select id="id"><option value="0">A</option></select>').appendTo('#test');
SelectFilter.init('id', 'things', 0);
assert.equal($('#test').children().first().prop("tagName"), "DIV");
assert.equal($('#test').children().first().attr("class"), "selector");
assert.equal($('.selector-available h2').text().trim(), "Available things");
assert.equal($('.selector-chosen h2').text().trim(), "Chosen things");
assert.equal($('.selector-chosen select')[0].getAttribute('multiple'), '');
Expand Down

0 comments on commit 471fa92

Please sign in to comment.