use element.clientWidth for calcing cols

This commit is contained in:
joshuaboud 2022-06-13 17:52:52 -03:00
parent d08427cfde
commit f29af205c1
No known key found for this signature in database
GPG Key ID: 17EFB59E2A8BF50E

View File

@ -83,7 +83,7 @@
</template>
<script>
import { ref, inject, watch, onMounted, computed, onBeforeUnmount } from 'vue';
import { ref, inject, watch, onMounted, computed, onBeforeUnmount, onUpdated } from 'vue';
import Table from './Table.vue';
import { clipboardInjectionKey, notificationsInjectionKey, settingsInjectionKey } from '../keys';
import LoadingSpinner from './LoadingSpinner.vue';
@ -247,13 +247,13 @@ export default {
}
const getCols = () => {
const gridRect = gridRef.value?.getBoundingClientRect();
if (!gridRect)
const gridWidth = gridRef.value?.clientWidth;
if (!gridWidth)
return cols.value = 1;
const entryWidth = settings.directoryView?.gridEntrySize;
if (!entryWidth)
return cols.value = 1;
return cols.value = Math.floor(gridRect.width / entryWidth);
return cols.value = Math.floor(gridWidth / entryWidth);
}
onMounted(() => {
@ -262,6 +262,8 @@ export default {
window.addEventListener('resize', getCols);
});
onUpdated(getCols);
onBeforeUnmount(() => {
window.removeEventListener('resize', getCols);
});