Skip to content

Commit

Permalink
fix TextSummary so if one-line-summary="true", expansion works
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedhamidawan committed Nov 20, 2024
1 parent 76fbe94 commit dd653ee
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions client/src/components/Common/TextSummary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ interface Props {
maxLength?: number;
/** The text to summarize */
description: string;
/** If `true`, doesn't let unexpanded text go beyond height of one line */
/** If `true`, doesn't let unexpanded text go beyond height of one line
* and ignores `maxLength` */
oneLineSummary?: boolean;
/** If `true`, doesn't show expand/collapse buttons */
noExpand?: boolean;
Expand All @@ -25,8 +26,17 @@ const props = withDefaults(defineProps<Props>(), {
});
const showDetails = ref(false);
const refOneLineSummary = ref<HTMLElement | null>(null);
const textTooLong = computed(() => props.description.length > props.maxLength);
const textTooLong = computed(() => {
if (!props.oneLineSummary) {
return props.description.length > props.maxLength;
} else if (refOneLineSummary.value) {
return refOneLineSummary.value.scrollWidth > refOneLineSummary.value.clientWidth;
} else {
return false;
}
});
const text = computed(() =>
textTooLong.value && !showDetails.value
? props.description.slice(0, Math.round(props.maxLength - props.maxLength / 2)) + "..."
Expand All @@ -35,8 +45,12 @@ const text = computed(() =>
</script>

<template>
<div>
<component :is="props.component" v-if="props.oneLineSummary" class="one-line-summary">
<div :class="{ 'd-flex': props.oneLineSummary && !noExpand }">
<component
:is="props.component"
v-if="props.oneLineSummary"
ref="refOneLineSummary"
:class="{ 'one-line-summary': !showDetails }">
{{ props.description }}
</component>
<span v-else>{{ text }}</span>
Expand Down

0 comments on commit dd653ee

Please sign in to comment.