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

feat(timepicker): activate type="number" for inputs #3236

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,4 +1,4 @@
import {Key, ElementFinder} from 'protractor';
import {Key, ElementFinder, browser} from 'protractor';

import {openUrl, expectFocused, sendKey, getCaretPosition} from '../../tools.po';

Expand Down Expand Up @@ -45,6 +45,16 @@ describe('Timepicker', () => {
describe('arrow keys', () => {
it(`should keep caret at the end of the input`, async() => {
const testField = async(fieldElement: ElementFinder) => {

const type = await browser.executeScript(
`
var element = arguments[0];
var type = element.getAttribute('type');
element.setAttribute('type', 'text');
return type;
`,
fieldElement.getWebElement());

await fieldElement.click();

const endPosition = 2;
Expand All @@ -67,6 +77,9 @@ describe('Timepicker', () => {

await sendKey(Key.ARROW_DOWN);
await expectCaretAtEnd();

await browser.executeScript(
`arguments[0].setAttribute('type', arguments[1]);`, fieldElement.getWebElement(), type);
};

for (const fieldElement of page.getFields()) {
Expand Down
7 changes: 7 additions & 0 deletions src/timepicker/timepicker.scss
Expand Up @@ -33,6 +33,13 @@ ngb-timepicker {

&-input {
text-align: center;
appearance: textfield;

&::-webkit-inner-spin-button,
&::-webkit-outer-spin-button {
appearance: none;
margin: 0;
}
}

&-hour,
Expand Down
6 changes: 3 additions & 3 deletions src/timepicker/timepicker.ts
Expand Up @@ -37,7 +37,7 @@ const NGB_TIMEPICKER_VALUE_ACCESSOR = {
<span class="chevron ngb-tp-chevron"></span>
<span class="sr-only" i18n="@@ngb.timepicker.increment-hours">Increment hours</span>
</button>
<input type="text" class="ngb-tp-input form-control" [class.form-control-sm]="isSmallSize" [class.form-control-lg]="isLargeSize"
<input type="number" class="ngb-tp-input form-control" [class.form-control-sm]="isSmallSize" [class.form-control-lg]="isLargeSize"
maxlength="2" placeholder="HH" i18n-placeholder="@@ngb.timepicker.HH"
[value]="formatHour(model?.hour)" (change)="updateHour($event.target.value)"
[readOnly]="readonlyInputs" [disabled]="disabled" aria-label="Hours" i18n-aria-label="@@ngb.timepicker.hours"
Expand All @@ -58,7 +58,7 @@ const NGB_TIMEPICKER_VALUE_ACCESSOR = {
<span class="chevron ngb-tp-chevron"></span>
<span class="sr-only" i18n="@@ngb.timepicker.increment-minutes">Increment minutes</span>
</button>
<input type="text" class="ngb-tp-input form-control" [class.form-control-sm]="isSmallSize" [class.form-control-lg]="isLargeSize"
<input type="number" class="ngb-tp-input form-control" [class.form-control-sm]="isSmallSize" [class.form-control-lg]="isLargeSize"
maxlength="2" placeholder="MM" i18n-placeholder="@@ngb.timepicker.MM"
[value]="formatMinSec(model?.minute)" (change)="updateMinute($event.target.value)"
[readOnly]="readonlyInputs" [disabled]="disabled" aria-label="Minutes" i18n-aria-label="@@ngb.timepicker.minutes"
Expand All @@ -79,7 +79,7 @@ const NGB_TIMEPICKER_VALUE_ACCESSOR = {
<span class="chevron ngb-tp-chevron"></span>
<span class="sr-only" i18n="@@ngb.timepicker.increment-seconds">Increment seconds</span>
</button>
<input type="text" class="ngb-tp-input form-control" [class.form-control-sm]="isSmallSize" [class.form-control-lg]="isLargeSize"
<input type="number" class="ngb-tp-input form-control" [class.form-control-sm]="isSmallSize" [class.form-control-lg]="isLargeSize"
maxlength="2" placeholder="SS" i18n-placeholder="@@ngb.timepicker.SS"
[value]="formatMinSec(model?.second)" (change)="updateSecond($event.target.value)"
[readOnly]="readonlyInputs" [disabled]="disabled" aria-label="Seconds" i18n-aria-label="@@ngb.timepicker.seconds"
Expand Down