Skip to content

Commit

Permalink
Allow changing the placeholder text of ipl-upload
Browse files Browse the repository at this point in the history
  • Loading branch information
inkfarer committed Apr 7, 2024
1 parent 41f7693 commit b20c710
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 3.3.0

- Add an `errorMessage` prop to ipl-button to allow changing the message that appears when an async action fails
- Add an `errorMessage` prop to ipl-button to allow changing the message that appears when an async action fails
- Allow changing the placeholder text of ipl-upload
- Fix the `progressMessage` prop of ipl-button doing nothing
- Fix ipl-checkbox visuals sometimes disappearing with long labels

Expand Down
5 changes: 4 additions & 1 deletion docs/examples/UploadExample.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
<div class="vertical-layout width-capped-content">
<!-- #region example -->
<div>Uploaded file: {{ file?.name }}</div>
<ipl-upload v-model="file" />
<ipl-upload
v-model="file"
placeholder="Click to upload a file..."
/>
<!-- #endregion example -->
</div>
</template>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`IplUpload shows custom message if no file is uploaded 1`] = `"<label class="ipl-upload"><span>Upload a file!</span><input type="file"></label>"`;
exports[`IplUpload shows file data if a file is uploaded 1`] = `
"<label class="ipl-upload">
<font-awesome-icon-stub icon="[object Object]" border="false" fixedwidth="false" flip="false" listitem="false" pulse="false" swapopacity="false" spin="false" symbol="false" inverse="false" bounce="false" shake="false" beat="false" fade="false" beatfade="false" flash="false" spinpulse="false" spinreverse="false" class="icon"></font-awesome-icon-stub><span>mock-file.jpg</span><input type="file">
</label>"
`;
exports[`IplUpload shows message if no file is uploaded 1`] = `"<label class="ipl-upload"><span> Drag a file here or<br> click to browse... </span><input type="file"></label>"`;
exports[`IplUpload shows message if no file is uploaded 1`] = `"<label class="ipl-upload"><span>Drag a file here or click to browse...</span><input type="file"></label>"`;
6 changes: 6 additions & 0 deletions src/components/__tests__/iplUpload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ describe('IplUpload', () => {
expect(wrapper.html()).toMatchSnapshot();
});

it('shows custom message if no file is uploaded', () => {
const wrapper = mount(IplUpload, { props: { modelValue: null, placeholder: 'Upload a file!' } });

expect(wrapper.html()).toMatchSnapshot();
});

it('emits update when a file is dropped onto the element', async () => {
const mockFile = new File([], 'mock-file');
const wrapper = mount(IplUpload, { props: { modelValue: null } });
Expand Down
7 changes: 5 additions & 2 deletions src/components/iplUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
@drop="handleDrop"
>
<span v-if="!modelValue">
Drag a file here or<br>
click to browse...
{{ placeholder }}
</span>
<template v-else>
<font-awesome-icon
Expand Down Expand Up @@ -38,6 +37,10 @@ export default defineComponent({
modelValue: {
type: [File, null] as PropType<File | null>,
required: true
},
placeholder: {
type: String,
default: 'Drag a file here or click to browse...',
}
},
Expand Down

0 comments on commit b20c710

Please sign in to comment.