Skip to content

Commit

Permalink
Merge branch 'master' into master-xmr-docs-a11y
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR authored Aug 21, 2019
2 parents c7c0c92 + 66e9ab3 commit afc91e6
Show file tree
Hide file tree
Showing 19 changed files with 141 additions and 74 deletions.
1 change: 1 addition & 0 deletions build/change-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function main(args) {
const newVersion = args[1]
const EXCLUDED_DIRS = new Set([
'.git',
'_gh_pages',
'node_modules',
'vendor'
])
Expand Down
11 changes: 8 additions & 3 deletions js/src/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,17 @@ const Default = {
flip: true,
boundary: 'scrollParent',
reference: 'toggle',
display: 'dynamic'
display: 'dynamic',
popperConfig: null
}

const DefaultType = {
offset: '(number|string|function)',
flip: 'boolean',
boundary: '(string|element)',
reference: '(string|element)',
display: 'string'
display: 'string',
popperConfig: '(null|object)'
}

/**
Expand Down Expand Up @@ -359,7 +361,10 @@ class Dropdown {
}
}

return popperConfig
return {
...popperConfig,
...this._config.popperConfig
}
}

// Static
Expand Down
22 changes: 22 additions & 0 deletions js/src/dropdown/dropdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,28 @@ describe('Dropdown', () => {

expect(dropdown.toggle).toHaveBeenCalled()
})

it('should allow to pass config to popper.js with `popperConfig`', () => {
fixtureEl.innerHTML = [
'<div class="dropdown">',
' <button href="#" class="btn dropdown-toggle" data-toggle="dropdown">Dropdown</button>',
' <div class="dropdown-menu">',
' <a class="dropdown-item" href="#">Secondary link</a>',
' </div>',
'</div>'
].join('')

const btnDropdown = fixtureEl.querySelector('[data-toggle="dropdown"]')
const dropdown = new Dropdown(btnDropdown, {
popperConfig: {
placement: 'left'
}
})

const popperConfig = dropdown._getPopperConfig()

expect(popperConfig.placement).toEqual('left')
})
})

describe('toggle', () => {
Expand Down
63 changes: 35 additions & 28 deletions js/src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const DefaultType = {
boundary: '(string|element)',
sanitize: 'boolean',
sanitizeFn: '(null|function)',
whiteList: 'object'
whiteList: 'object',
popperConfig: '(null|object)'
}

const AttachmentMap = {
Expand Down Expand Up @@ -84,7 +85,8 @@ const Default = {
boundary: 'scrollParent',
sanitize: true,
sanitizeFn: null,
whiteList: DefaultWhitelist
whiteList: DefaultWhitelist,
popperConfig: null
}

const HoverState = {
Expand Down Expand Up @@ -129,10 +131,6 @@ const Trigger = {

class Tooltip {
constructor(element, config) {
/**
* Check for Popper dependency
* Popper - https://popper.js.org
*/
if (typeof Popper === 'undefined') {
throw new TypeError('Bootstrap\'s tooltips require Popper.js (https://popper.js.org)')
}
Expand Down Expand Up @@ -247,7 +245,7 @@ class Tooltip {
this._timeout = null
this._hoverState = null
this._activeTrigger = null
if (this._popper !== null) {
if (this._popper) {
this._popper.destroy()
}

Expand Down Expand Up @@ -301,27 +299,7 @@ class Tooltip {

EventHandler.trigger(this.element, this.constructor.Event.INSERTED)

this._popper = new Popper(this.element, tip, {
placement: attachment,
modifiers: {
offset: this._getOffset(),
flip: {
behavior: this.config.fallbackPlacement
},
arrow: {
element: `.${this.constructor.NAME}-arrow`
},
preventOverflow: {
boundariesElement: this.config.boundary
}
},
onCreate: data => {
if (data.originalPlacement !== data.placement) {
this._handlePopperPlacementChange(data)
}
},
onUpdate: data => this._handlePopperPlacementChange(data)
})
this._popper = new Popper(this.element, tip, this._getPopperConfig(attachment))

tip.classList.add(ClassName.SHOW)

Expand Down Expand Up @@ -482,6 +460,35 @@ class Tooltip {

// Private

_getPopperConfig(attachment) {
const defaultBsConfig = {
placement: attachment,
modifiers: {
offset: this._getOffset(),
flip: {
behavior: this.config.fallbackPlacement
},
arrow: {
element: `.${this.constructor.NAME}-arrow`
},
preventOverflow: {
boundariesElement: this.config.boundary
}
},
onCreate: data => {
if (data.originalPlacement !== data.placement) {
this._handlePopperPlacementChange(data)
}
},
onUpdate: data => this._handlePopperPlacementChange(data)
}

return {
...defaultBsConfig,
...this.config.popperConfig
}
}

_addAttachmentClass(attachment) {
this.getTipElement().classList.add(`${CLASS_PREFIX}-${attachment}`)
}
Expand Down
15 changes: 15 additions & 0 deletions js/src/tooltip/tooltip.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ describe('Tooltip', () => {

tooltipInContainerEl.click()
})

it('should allow to pass config to popper.js with `popperConfig`', () => {
fixtureEl.innerHTML = '<a href="#" rel="tooltip"/>'

const tooltipEl = fixtureEl.querySelector('a')
const tooltip = new Tooltip(tooltipEl, {
popperConfig: {
placement: 'left'
}
})

const popperConfig = tooltip._getPopperConfig('top')

expect(popperConfig.placement).toEqual('left')
})
})

describe('enable', () => {
Expand Down
6 changes: 3 additions & 3 deletions scss/_reboot.scss
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,9 @@ progress {
// Fix height of inputs with a type of datetime-local, date, month, week, or time
// See https://github.com/twbs/bootstrap/issues/18842

::-webkit-inner-spin-button,
::-webkit-outer-spin-button {
height: 0;
::-webkit-datetime-edit {
overflow: visible;
line-height: 0;
}


Expand Down
37 changes: 20 additions & 17 deletions scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ $input-line-height-lg: $input-btn-line-height-lg !default;

$input-bg: $white !default;
$input-disabled-bg: $gray-200 !default;
$input-disabled-border-color: null !default;

$input-color: $gray-700 !default;
$input-border-color: $gray-400 !default;
Expand Down Expand Up @@ -581,23 +582,24 @@ $input-group-addon-bg: $gray-200 !default;
$input-group-addon-border-color: $input-border-color !default;


$form-select-padding-y: $input-padding-y !default;
$form-select-padding-x: $input-padding-x !default;
$form-select-font-family: $input-font-family !default;
$form-select-font-size: $input-font-size !default;
$form-select-height: $input-height !default;
$form-select-indicator-padding: 1rem !default; // Extra padding to account for the presence of the background-image based indicator
$form-select-font-weight: $input-font-weight !default;
$form-select-line-height: $input-line-height !default;
$form-select-color: $input-color !default;
$form-select-disabled-color: $gray-600 !default;
$form-select-bg: $input-bg !default;
$form-select-disabled-bg: $gray-200 !default;
$form-select-bg-size: 16px 12px !default; // In pixels because image dimensions
$form-select-indicator-color: $gray-800 !default;
$form-select-indicator: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path fill='none' stroke='#{$form-select-indicator-color}' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/></svg>") !default;

$form-select-background: no-repeat right $form-select-padding-x center / $form-select-bg-size !default; // Used so we can have multiple background elements (e.g., arrow and feedback icon)
$form-select-padding-y: $input-padding-y !default;
$form-select-padding-x: $input-padding-x !default;
$form-select-font-family: $input-font-family !default;
$form-select-font-size: $input-font-size !default;
$form-select-height: $input-height !default;
$form-select-indicator-padding: 1rem !default; // Extra padding to account for the presence of the background-image based indicator
$form-select-font-weight: $input-font-weight !default;
$form-select-line-height: $input-line-height !default;
$form-select-color: $input-color !default;
$form-select-disabled-color: $gray-600 !default;
$form-select-bg: $input-bg !default;
$form-select-disabled-bg: $gray-200 !default;
$form-select-disabled-border-color: $input-disabled-border-color !default;
$form-select-bg-size: 16px 12px !default; // In pixels because image dimensions
$form-select-indicator-color: $gray-800 !default;
$form-select-indicator: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path fill='none' stroke='#{$form-select-indicator-color}' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/></svg>") !default;

$form-select-background: no-repeat right $form-select-padding-x center / $form-select-bg-size !default; // Used so we can have multiple background elements (e.g., arrow and feedback icon)

$form-select-feedback-icon-padding-right: calc((1em + #{2 * $form-select-padding-y}) * 3 / 4 + #{$form-select-padding-x + $form-select-indicator-padding}) !default;
$form-select-feedback-icon-position: center right ($form-select-padding-x + $form-select-indicator-padding) !default;
Expand Down Expand Up @@ -645,6 +647,7 @@ $form-file-height: $input-height !default;
$form-file-focus-border-color: $input-focus-border-color !default;
$form-file-focus-box-shadow: $input-focus-box-shadow !default;
$form-file-disabled-bg: $input-disabled-bg !default;
$form-file-disabled-border-color: $input-disabled-border-color !default;

$form-file-padding-y: $input-padding-y !default;
$form-file-padding-x: $input-padding-x !default;
Expand Down
11 changes: 4 additions & 7 deletions scss/forms/_form-control.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
.form-control {
display: block;
width: 100%;
height: $input-height;
min-height: $input-height;
padding: $input-padding-y $input-padding-x;
font-family: $input-font-family;
@include font-size($input-font-size);
Expand Down Expand Up @@ -59,6 +59,7 @@
&:disabled,
&[readonly] {
background-color: $input-disabled-bg;
border-color: $input-disabled-border-color;
// iOS fix for unreadable disabled content; see https://github.com/twbs/bootstrap/issues/11655.
opacity: 1;
}
Expand Down Expand Up @@ -95,21 +96,17 @@
// Repeated in `_input_group.scss` to avoid Sass extend issues.

.form-control-sm {
height: $input-height-sm;
min-height: $input-height-sm;
padding: $input-padding-y-sm $input-padding-x-sm;
@include font-size($input-font-size-sm);
line-height: $input-line-height-sm;
@include border-radius($input-border-radius-sm);
}

.form-control-lg {
height: $input-height-lg;
min-height: $input-height-lg;
padding: $input-padding-y-lg $input-padding-x-lg;
@include font-size($input-font-size-lg);
line-height: $input-line-height-lg;
@include border-radius($input-border-radius-lg);
}

textarea.form-control {
height: auto;
}
1 change: 1 addition & 0 deletions scss/forms/_form-file.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
// Workaround for: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/11295231
&[disabled] ~ .form-file-label .form-file-text {
background-color: $form-file-disabled-bg;
border-color: $form-file-disabled-border-color;
}
}

Expand Down
1 change: 1 addition & 0 deletions scss/forms/_form-select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
&:disabled {
color: $form-select-disabled-color;
background-color: $form-select-disabled-bg;
border-color: $form-select-disabled-border-color;
}

// Hides the default caret in IE11
Expand Down
10 changes: 8 additions & 2 deletions scss/forms/_input-group.scss
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@
// Remix the default form control sizing classes into new ones for easier
// manipulation.

.input-group-lg > .form-control:not(textarea),
.input-group-lg > .form-control {
min-height: $input-height-lg;
}

.input-group-lg > .form-select {
height: $input-height-lg;
}
Expand All @@ -140,7 +143,10 @@
@include border-radius($input-border-radius-lg);
}

.input-group-sm > .form-control:not(textarea),
.input-group-sm > .form-control {
min-height: $input-height-sm;
}

.input-group-sm > .form-select {
height: $input-height-sm;
}
Expand Down
6 changes: 6 additions & 0 deletions site/content/docs/4.3/components/dropdowns.md
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,12 @@ Options can be passed via data attributes or JavaScript. For data attributes, ap
<td>'dynamic'</td>
<td>By default, we use Popper.js for dynamic positioning. Disable this with <code>static</code>.</td>
</tr>
<tr>
<td>popperConfig</td>
<td>null | object</td>
<td>null</td>
<td>To change Bootstrap's default Popper.js config, see <a href="https://popper.js.org/popper-documentation.html#Popper.Defaults">Popper.js's configuration</a></td>
</tr>
</tbody>
</table>

Expand Down
6 changes: 6 additions & 0 deletions site/content/docs/4.3/components/popovers.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ Note that for security reasons the `sanitize`, `sanitizeFn` and `whiteList` opti
<td>null</td>
<td>Here you can supply your own sanitize function. This can be useful if you prefer to use a dedicated library to perform sanitization.</td>
</tr>
<tr>
<td>popperConfig</td>
<td>null | object</td>
<td>null</td>
<td>To change Bootstrap's default Popper.js config, see <a href="https://popper.js.org/popper-documentation.html#Popper.Defaults">Popper.js's configuration</a></td>
</tr>
</tbody>
</table>

Expand Down
6 changes: 6 additions & 0 deletions site/content/docs/4.3/components/tooltips.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ Note that for security reasons the `sanitize`, `sanitizeFn` and `whiteList` opti
<td>null</td>
<td>Here you can supply your own sanitize function. This can be useful if you prefer to use a dedicated library to perform sanitization.</td>
</tr>
<tr>
<td>popperConfig</td>
<td>null | object</td>
<td>null</td>
<td>To change Bootstrap's default Popper.js config, see <a href="https://popper.js.org/popper-documentation.html#Popper.Defaults">Popper.js's configuration</a></td>
</tr>
</tbody>
</table>

Expand Down
Loading

0 comments on commit afc91e6

Please sign in to comment.