Skip to content

Commit

Permalink
feat: allow specifying input type
Browse files Browse the repository at this point in the history
  • Loading branch information
veelci committed May 10, 2024
1 parent e69444c commit fae53c3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion addon/components/input-credit-card-cvc.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Input
@type="tel"
@type={{this.type}}
@value={{this.cvc}}
class="input-credit-card-cvc"
placeholder="•••"
Expand Down
4 changes: 4 additions & 0 deletions addon/components/input-credit-card-cvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ function inputValid(value) {
}

export default class InputCreditCardCvcComponent extends Component {
get type() {
return this.args.type || 'tel';
}

get cvc() {
return formatters.formatCvc(this.args.cvc);
}
Expand Down
2 changes: 1 addition & 1 deletion addon/components/input-credit-card-number.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Input
@type="tel"
@type={{this.type}}
@value={{this.number}}
autocomplete="cc-number"
class="input-credit-card-number"
Expand Down
4 changes: 4 additions & 0 deletions addon/components/input-credit-card-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ function inputValid(value) {
}

export default class InputCreditCardNumberComponent extends Component {
get type() {
return this.args.type || 'tel';
}

get number() {
return formatters.formatNumber(this.args.number);
}
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/components/input-credit-card-cvc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ module('Integration | Component | input-credit-card-cvc', function (hooks) {

assert.equal(this.element.querySelector('.form-control').value, '300');
});

test('it can specify the input type', async function (assert) {
await render(hbs`<InputCreditCardCvc @type="password" />`);

assert.dom('input').hasAttribute('type', 'password');
});
});
6 changes: 6 additions & 0 deletions tests/integration/components/input-credit-card-number-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,10 @@ module('Integration | Component | input-credit-card-number', function (hooks) {
await typeIn('input', '1');
assert.equal(this.number, '4111111111111111');
});

test('it can specify the input type', async function (assert) {
await render(hbs`<InputCreditCardNumber @type="password" />`);

assert.dom('input').hasAttribute('type', 'password');
});
});

0 comments on commit fae53c3

Please sign in to comment.