From d4319678206e0f1ff757b1852fa34532219a8c33 Mon Sep 17 00:00:00 2001 From: Julian Walther Date: Mon, 17 Dec 2018 16:10:28 +0100 Subject: [PATCH] proposal: add inital value for input of prompt toasts this enhances user experience when using prompt toasts for tasks like renaming things... --- docs/api/options.md | 6 ++++++ example/src/App/app.ts | 5 +++-- example/test/unit/specs/Prompt.spec.ts | 11 +++++++++++ src/components/SnotifyPrompt.vue | 1 + src/components/toast.model.ts | 2 +- src/interfaces/SnotifyToastConfig.interface.ts | 6 ++++++ src/toastDefaults.ts | 1 + 7 files changed, 29 insertions(+), 3 deletions(-) diff --git a/docs/api/options.md b/docs/api/options.md index 3da9893..c388ed8 100644 --- a/docs/api/options.md +++ b/docs/api/options.md @@ -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` diff --git a/example/src/App/app.ts b/example/src/App/app.ts index ccab3ea..ac597ae 100644 --- a/example/src/App/app.ts +++ b/example/src/App/app.ts @@ -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'); }); diff --git a/example/test/unit/specs/Prompt.spec.ts b/example/test/unit/specs/Prompt.spec.ts index 7d52dd8..3568558 100644 --- a/example/test/unit/specs/Prompt.spec.ts +++ b/example/test/unit/specs/Prompt.spec.ts @@ -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(); + }); + }); }); diff --git a/src/components/SnotifyPrompt.vue b/src/components/SnotifyPrompt.vue index 0e58a3b..4fff023 100644 --- a/src/components/SnotifyPrompt.vue +++ b/src/components/SnotifyPrompt.vue @@ -1,6 +1,7 @@