Skip to content

Commit 0533782

Browse files
authored
feat(calendar): support context setting
A calendar popup inside an overflowing container does not allow the popup to be shown completely, because it's still inside the overflowing container of the related calendar input field You can now use a context setting which will move the calendar popup outside of the overflowing container (if the given context isnt an overflowing container itself...)
1 parent ead2efb commit 0533782

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

src/definitions/collections/table.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,8 +1556,8 @@
15561556
border-color: @invertedCellBorderColor;
15571557
}
15581558
& when (@variationTableDisabled) {
1559-
.ui.inverted.table tr.disabled td,
1560-
.ui.inverted.table tr td.disabled,
1559+
.ui.ui.ui.inverted.table tr.disabled td,
1560+
.ui.ui.ui.inverted.table tr td.disabled,
15611561
.ui.inverted.table tr.disabled:hover td,
15621562
.ui.inverted.table tr:hover td.disabled {
15631563
pointer-events: none;

src/definitions/modules/calendar.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ window = (typeof window != 'undefined' && window.Math == Math)
2626
$.fn.calendar = function(parameters) {
2727
var
2828
$allModules = $(this),
29+
$document = $(document),
2930

3031
moduleSelector = $allModules.selector || '',
3132

@@ -67,11 +68,11 @@ $.fn.calendar = function(parameters) {
6768

6869
$module = $(this),
6970
$input = $module.find(selector.input),
70-
$container = $module.find(selector.popup),
7171
$activator = $module.find(selector.activator),
7272

7373
element = this,
7474
instance = $module.data(moduleNamespace),
75+
$container = instance && instance.popupId ? $document.find('#'+instance.popupId) : $module.find(selector.popup),
7576

7677
isTouch,
7778
isTouchDown = false,
@@ -139,11 +140,16 @@ $.fn.calendar = function(parameters) {
139140
return;
140141
}
141142
if (!$container.length) {
142-
//prepend the popup element to the activator's parent so that it has less chance of messing with
143-
//the styling (eg input action button needs to be the last child to have correct border radius)
144-
var $activatorParent = $activator.parent(),
145-
domPositionFunction = $activatorParent.closest(selector.append).length !== 0 ? 'appendTo' : 'prependTo';
146-
$container = $('<div/>').addClass(className.popup)[domPositionFunction]($activatorParent);
143+
if(settings.context) {
144+
module.popupId = namespace + '_popup_' + (Math.random().toString(16) + '000000000').slice(2, 10);
145+
$container = $('<div/>',{id:module.popupId}).addClass(className.popup).appendTo($document.find(settings.context));
146+
} else {
147+
//prepend the popup element to the activator's parent so that it has less chance of messing with
148+
//the styling (eg input action button needs to be the last child to have correct border radius)
149+
var $activatorParent = $activator.parent(),
150+
domPositionFunction = $activatorParent.closest(selector.append).length !== 0 ? 'appendTo' : 'prependTo';
151+
$container = $('<div/>').addClass(className.popup)[domPositionFunction]($activatorParent);
152+
}
147153
}
148154
$container.addClass(className.calendar);
149155
if(isInverted){
@@ -175,6 +181,7 @@ $.fn.calendar = function(parameters) {
175181
var on = module.setting('on');
176182
var options = $.extend({}, settings.popupOptions, {
177183
popup: $container,
184+
movePopup: !settings.context,
178185
on: on,
179186
hoverable: on === 'hover',
180187
closable: on === 'click',
@@ -805,7 +812,7 @@ $.fn.calendar = function(parameters) {
805812
return null;
806813
}
807814
if (!(selector instanceof $)) {
808-
selector = $(document).find(selector).first();
815+
selector = $document.find(selector).first();
809816
}
810817
//assume range related calendars are using the same namespace
811818
return selector.data(moduleNamespace);
@@ -1490,6 +1497,8 @@ $.fn.calendar.settings = {
14901497
verbose: false,
14911498
performance: true,
14921499

1500+
context : false,
1501+
14931502
type : 'datetime', // picker type, can be 'datetime', 'date', 'time', 'month', or 'year'
14941503
firstDayOfWeek : 0, // day for first day column (0 = Sunday)
14951504
constantHeight : true, // add rows to shorter months to keep day calendar height consistent (6 rows)

src/definitions/modules/calendar.less

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,35 @@
2121
Popup
2222
*******************************/
2323

24-
.ui.calendar .ui.popup {
24+
.ui.calendar.popup {
2525
max-width: none;
2626
padding: 0;
2727
border: none;
2828
user-select: none;
29+
&.inverted::before when (@variationCalendarInverted) {
30+
background: @invertedArrowBackground;
31+
}
2932
}
3033

3134
/*******************************
3235
Calendar
3336
*******************************/
3437

35-
.ui.calendar .calendar:focus {
38+
.ui.calendar .calendar:focus,
39+
.ui.calendar.popup:focus {
3640
outline: 0;
3741
}
3842

3943
/*******************************
4044
Grid
4145
*******************************/
4246

43-
.ui.calendar .ui.popup .ui.grid {
47+
.ui.calendar.popup .ui.grid {
4448
display: block;
4549
white-space: nowrap;
4650
}
4751

48-
.ui.calendar .ui.popup .ui.grid > .column {
52+
.ui.calendar.popup .ui.grid > .column {
4953
width: auto;
5054
}
5155

@@ -146,8 +150,8 @@
146150
box-shadow: @rangeBoxShadow;
147151
}
148152

149-
.ui.calendar:not(.disabled) .calendar:focus .ui.table tbody tr td.focus,
150-
.ui.calendar:not(.disabled) .calendar.active .ui.table tbody tr td.focus {
153+
.ui.calendar:not(.disabled):focus .ui.table tbody tr td.focus,
154+
.ui.calendar:not(.disabled).popup.active .ui.table tbody tr td.focus {
151155
box-shadow: @focusBoxShadow;
152156
}
153157

@@ -159,10 +163,10 @@
159163
}
160164

161165
.ui.inverted.calendar:not(.disabled) .calendar:focus .ui.table.inverted tbody tr td.focus,
162-
.ui.inverted.calendar:not(.disabled) .calendar.active .ui.table.inverted tbody tr td.focus {
166+
.ui.inverted.calendar:not(.disabled).popup.active .ui.table.inverted tbody tr td.focus {
163167
box-shadow: @focusInvertedBoxShadow;
164168
}
165-
.ui.inverted.calendar .ui.inverted.table tr .disabled {
169+
.ui.inverted.calendar .ui.ui.ui.inverted.table tr .disabled {
166170
color: @invertedDisabledTextColor;
167171
}
168172

src/themes/default/modules/calendar.variables

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
@rangeInvertedTextColor: @invertedSelectedTextColor;
1515
@rangeInvertedBoxShadow: none;
1616

17+
@invertedArrowBackground: #2b2b2b;
18+
1719
@adjacentTextColor: @mutedTextColor;
1820
@adjacentBackground: @subtleTransparentBlack;
1921
@adjacentInvertedTextColor: @invertedMutedTextColor;

0 commit comments

Comments
 (0)