Fixed #224 for MultiSelect

pull/227/head
cagataycivici 2020-03-04 14:36:30 +03:00
parent e8c6eb324e
commit 819b5d5ac7
4 changed files with 38 additions and 3 deletions

View File

@ -301,7 +301,7 @@ export default {
alignOverlay() { alignOverlay() {
if (this.appendTo) { if (this.appendTo) {
DomHandler.absolutePosition(this.$refs.overlay, this.$refs.container); DomHandler.absolutePosition(this.$refs.overlay, this.$refs.container);
this.$refs.overlay.style.width = DomHandler.getOuterWidth(this.$refs.container) + 'px'; this.$refs.overlay.style.minWidth = DomHandler.getOuterWidth(this.$refs.container) + 'px';
} else { } else {
DomHandler.relativePosition(this.$refs.overlay, this.$refs.container); DomHandler.relativePosition(this.$refs.overlay, this.$refs.container);
} }

View File

@ -14,6 +14,7 @@ export declare class MultiSelect extends Vue {
dataKey?: string; dataKey?: string;
filterPlaceholder?: string; filterPlaceholder?: string;
ariaLabelledBy?: string; ariaLabelledBy?: string;
appendTo?: string;
$emit(eventName: 'input', value: any): this; $emit(eventName: 'input', value: any): this;
$emit(eventName: 'change', e: {originalEvent: Event, value: any}): this; $emit(eventName: 'change', e: {originalEvent: Event, value: any}): this;
$emit(eventName: 'before-show'): this; $emit(eventName: 'before-show'): this;

View File

@ -74,7 +74,11 @@ export default {
tabindex: String, tabindex: String,
dataKey: null, dataKey: null,
filterPlaceholder: String, filterPlaceholder: String,
ariaLabelledBy: null ariaLabelledBy: null,
appendTo: {
type: String,
default: null
}
}, },
data() { data() {
return { return {
@ -86,6 +90,7 @@ export default {
}, },
outsideClickListener: null, outsideClickListener: null,
beforeDestroy() { beforeDestroy() {
this.restoreAppend();
this.unbindOutsideClickListener(); this.unbindOutsideClickListener();
}, },
updated() { updated() {
@ -253,6 +258,7 @@ export default {
return null; return null;
}, },
onOverlayEnter() { onOverlayEnter() {
this.appendContainer();
this.alignOverlay(); this.alignOverlay();
this.bindOutsideClickListener(); this.bindOutsideClickListener();
this.$emit('show'); this.$emit('show');
@ -262,7 +268,13 @@ export default {
this.$emit('hide'); this.$emit('hide');
}, },
alignOverlay() { alignOverlay() {
if (this.appendTo) {
DomHandler.absolutePosition(this.$refs.overlay, this.$refs.container);
this.$refs.overlay.style.minWidth = DomHandler.getOuterWidth(this.$refs.container) + 'px';
}
else {
DomHandler.relativePosition(this.$refs.overlay, this.$refs.container); DomHandler.relativePosition(this.$refs.overlay, this.$refs.container);
}
}, },
bindOutsideClickListener() { bindOutsideClickListener() {
if (!this.outsideClickListener) { if (!this.outsideClickListener) {
@ -304,6 +316,22 @@ export default {
this.$emit('input', value); this.$emit('input', value);
this.$emit('change', {originalEvent: event, value: value}); this.$emit('change', {originalEvent: event, value: value});
},
appendContainer() {
if (this.appendTo) {
if (this.appendTo === 'body')
document.body.appendChild(this.$refs.overlay);
else
document.getElementById(this.appendTo).appendChild(this.$refs.overlay);
}
},
restoreAppend() {
if (this.$refs.overlay && this.appendTo) {
if (this.appendTo === 'body')
document.body.removeChild(this.$refs.overlay);
else
document.getElementById(this.appendTo).removeChild(this.$refs.overlay);
}
} }
}, },
computed: { computed: {

View File

@ -153,6 +153,12 @@ data() {
<td>string</td> <td>string</td>
<td>null</td> <td>null</td>
<td>Establishes relationships between the component and label(s) where its value should be one or more element IDs.</td> <td>Establishes relationships between the component and label(s) where its value should be one or more element IDs.</td>
</tr>
<tr>
<td>appendTo</td>
<td>string</td>
<td>null</td>
<td>Id of the element or "body" for document where the overlay should be appended to.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>