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

proposal: add inital value for input of prompt toasts #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions docs/api/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ Vue.use(Snotify, {
- default: `"Enter answer here..."`
> Placeholder for Prompt toast

### initialValue

- type: `string`
- default: `""`
> Inital value for Prompt toast

### titleMaxLength

- type: `number`
Expand Down
5 changes: 3 additions & 2 deletions example/src/App/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ export class App extends Vue {
{text: 'Yes', action: (toast) => console.log('Said Yes: ' + toast.value) },
{text: 'No', action: (toast) => { console.log('Said No: ' + toast.value); this.$snotify.remove(toast.id); }},
],
placeholder: 'Enter "ng-snotify" to validate this input' // Max-length = 40
placeholder: 'Enter "vue-snotify" to validate this input', // Max-length = 40
initialValue: 'ng-snotify'
}).on('input', (toast) => {
console.log(toast.value);
toast.valid = !!toast.value.match('ng-snotify');
toast.valid = !!toast.value.match('vue-snotify');
});


Expand Down
11 changes: 11 additions & 0 deletions example/test/unit/specs/Prompt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ describe('Prompt Toast', () => {
});
});
});

it('should set initial value', (done) => {
const toast = vm.$snotify.prompt('test', 'test2', {
initialValue: 'Hello'
});
vm.$nextTick(() => {
const node: HTMLInputElement = vm.$el.querySelector('.snotify.snotify-rightBottom .snotifyToast.snotify-prompt input');
expect(node.value).toEqual('Hello');
done();
});
});
});


1 change: 1 addition & 0 deletions src/components/SnotifyPrompt.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<span class="snotifyToast__input" :class="{'snotifyToast__input--filled': isPromptFocused}">
<input @input="valueChanged"
:value="toast.value"
class="snotifyToast__input__field" type="text"
:id="toast.id"
@focus="isPromptFocused = true"
Expand Down
2 changes: 1 addition & 1 deletion src/components/toast.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class SnotifyToast {
public body: string,
public config: SnotifyToastConfig) {
if (this.config.type === SnotifyStyle.prompt) {
this.value = '';
this.value = this.config.initialValue;
}
this.on('hidden', () => {
this._eventsHolder.forEach((o) => {
Expand Down
6 changes: 6 additions & 0 deletions src/interfaces/SnotifyToastConfig.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ export interface SnotifyToastConfig {
* @default 'Enter answer here...'
*/
placeholder?: string;
/**
* Initial input value for Prompt toast
* @type {string}
* @default ''
*/
initialValue?: string;
/**
* Toast title maximum length
* @type {number}
Expand Down
1 change: 1 addition & 0 deletions src/toastDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const ToastDefaults = {
{text: 'Cancel', action: null, bold: false},
],
placeholder: 'Enter answer here...',
initialValue: '',
type: SnotifyStyle.prompt,
},
[SnotifyStyle.confirm]: {
Expand Down