Created
February 25, 2019 14:41
-
-
Save Septdir/e12333e1ca8ad6d38e388de6e7fecd77 to your computer and use it in GitHub Desktop.
UIkit3 number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[input-number] input, | |
[input-number] input:focus, | |
[input-number] input:hover, | |
[input-number] input:active { | |
-webkit-appearance: textfield; | |
-moz-appearance: textfield; | |
appearance: textfield; | |
padding-right: 42px; | |
box-sizing: border-box; | |
} | |
[input-number] input::-webkit-outer-spin-button, | |
[input-number] input::-webkit-inner-spin-button { | |
-webkit-appearance: none; | |
margin: 0; | |
} | |
[input-number] .uk-form-icon-flip ~ .uk-input { | |
padding-right: 62px !important; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="uk-position-relative uk-inline" input-number> | |
<input id="quantity" type="number" name="quantity" class="uk-input" step="1" min="1" value="1" /> | |
<div class="uk-position-center-right"> | |
<a class="plus uk-text-success" | |
uk-icon="icon: triangle-up"></a> | |
<hr class="uk-margin-remove"> | |
<a class="minus uk-text-danger" | |
uk-icon="icon: triangle-down"></a> | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener("DOMContentLoaded", function () { | |
// Number input | |
document.querySelectorAll('[input-number]').forEach(function (block) { | |
block.querySelector('.plus').addEventListener('click', function () { | |
changeValue('plus'); | |
}); | |
block.querySelector('.minus').addEventListener('click', function () { | |
changeValue('minus'); | |
}); | |
function changeValue(type) { | |
let input = block.querySelector('input'); | |
if (type === 'plus') { | |
input.stepUp(); | |
} else if (type === 'minus') { | |
input.stepDown(); | |
} | |
input.dispatchEvent(new Event('change', {'bubbles': true})) | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment