diff --git a/docs/components/truncate.md b/docs/components/truncate.md index 2a2ad581a0..7ca8713d39 100644 --- a/docs/components/truncate.md +++ b/docs/components/truncate.md @@ -1,6 +1,6 @@ # Truncate -**KTruncate** - A Kongponent that limits content to a specific number of lines and provides controls to show or hide the truncated content. +KTruncate - a container that limits content to a specific number of lines and provides controls to show or hide the hidden items. @@ -44,22 +44,22 @@ Number of rows to truncate content. Default value is `1`. ``` -### isTextContent +### truncateText By default the component treats anything passed through the `default` slot as collection of HTML elements. Use this prop if you want to truncate elements that only contain text, such as one or more paragraph `

` tags. When this prop is set to `true`, the component applies different logic; truncation is achieved via the `-webkit-line-clamp` CSS property, rather than assessing the height of child elements to determine the row height. - -

A good design decision to apply text truncation would be when displaying a large amount of textual content, such as a list of articles or product descriptions, in a limited space, such as a mobile screen or a small widget. By truncating the text to a short summary, it is possible to present the information in a more organized and readable manner, allowing the user to quickly scan and understand the main points of each item.

-

The truncated text can also serve as a teaser, encouraging the user to click or tap to view the full content.

+ +

A good design decision to apply text truncation would be when displaying a large amount of textual content, such as a list of articles or product descriptions, in a limited space, such as a mobile screen or a small widget. By truncating the text to a short summary, it is possible to present the information in a more organized and readable manner, allowing the user to quickly scan and understand the main points of each item.

+

The truncated text can also serve as a teaser, encouraging the user to click or tap to view the full content.

```html ``` -### isExpanded +### expanded When `true`, the component will not truncate the content and the collapse trigger will be visible. - + Item {{ n }} @@ -86,7 +86,7 @@ When `true`, the component will not truncate the content and the collapse trigge ```html ``` - diff --git a/docs/guide/migrating-to-version-9.md b/docs/guide/migrating-to-version-9.md index d6dcef37c1..b1b4f77e08 100644 --- a/docs/guide/migrating-to-version-9.md +++ b/docs/guide/migrating-to-version-9.md @@ -570,6 +570,18 @@ Removed as of `v9`. Use `KBreadcumbs` instead. ### KTruncate +#### Props + +* `isTextContent` prop has been changed to `truncateText` +* `isExpanded` prop has been changed to `expanded` + +#### Structure + +* `k-truncate-content` class has been changed to `truncate-content` +* `k-truncate-text` class has been changed to `truncate-text` +* `k-truncate-expand-controls` class has been changed to `truncate-expand-controls` +* `k-truncate-container` class has been changed to `truncate-container` +* `k-truncate-collapse-controls` class has been changed to `truncate-collapse-controls` ### KView Switcher diff --git a/src/components/KTruncate/KTruncate.cy.ts b/src/components/KTruncate/KTruncate.cy.ts index 6449d04b81..680bb74492 100644 --- a/src/components/KTruncate/KTruncate.cy.ts +++ b/src/components/KTruncate/KTruncate.cy.ts @@ -55,11 +55,11 @@ describe('KTruncate', () => { cy.get('[data-testid="expand-trigger-wrapper"]').should('contain.text', expandTriggerContent).click() }) - it('render expanded when isExpanded prop is true and render content passed in through expand trigger slot', () => { + it('render expanded when expanded prop is true and render content passed in through expand trigger slot', () => { const collapseTriggerContent = 'Collapse' mount(KTruncate, { props: { - isExpanded: true, + expanded: true, }, slots: { default: [ diff --git a/src/components/KTruncate/KTruncate.vue b/src/components/KTruncate/KTruncate.vue index 16bec779ca..f11413661e 100644 --- a/src/components/KTruncate/KTruncate.vue +++ b/src/components/KTruncate/KTruncate.vue @@ -2,13 +2,13 @@
value > 0, }, - isTextContent: { + truncateText: { type: Boolean, default: false, }, - isExpanded: { + expanded: { type: Boolean, default: false, }, @@ -120,7 +123,7 @@ const props = defineProps({ }, }) -const expanded = ref(props.isExpanded) +const expanded = ref(props.expanded) const showToggle = ref(false) @@ -145,7 +148,7 @@ const truncatedCount = ref(0) * For example if rows is 2 and all elements are equal height if 22px, wrapper height will be set to 54px (2 * 22 + gap). */ const setWrapperHeight = async (): Promise => { - if (props.isTextContent) { + if (props.truncateText) { return } @@ -173,7 +176,7 @@ const setWrapperHeight = async (): Promise => { const updateToggleVisibility = (): void => { if (kTruncateContainer.value && kTruncateWrapper.value) { // in case with text content, need to compare scrollHeight value - const containerHeightProperty = props.isTextContent ? kTruncateContainer.value.scrollHeight : kTruncateContainer.value.offsetHeight + const containerHeightProperty = props.truncateText ? kTruncateContainer.value.scrollHeight : kTruncateContainer.value.offsetHeight const textToggleControlsHeight = textToggleControls.value ? textToggleControls.value.offsetHeight : 0 /** * In case with text content, toggle controls element is rendered below content, so adds up to wrapper height. @@ -186,7 +189,7 @@ const updateToggleVisibility = (): void => { // Counts elements that are wrapped to the hidden rows and therefore are not visible. const countExcessElements = (): void => { - if (props.isTextContent) { + if (props.truncateText) { return } @@ -196,7 +199,7 @@ const countExcessElements = (): void => { for (let i = 0; i < children.length; i++) { /** * If element's offsetTop - * (offset from the nearest relatively positioned parent, which is .k-truncate-container) + * (offset from the nearest relatively positioned parent, which is .truncate-container) * is greater than the wrapper element height - means it's not visible */ if (children[i].offsetTop > kTruncateWrapper.value.offsetHeight) { @@ -247,18 +250,20 @@ onUnmounted(() => { overflow: hidden; padding: var(--kui-space-20, $kui-space-20); - .k-truncate-expand-controls { - align-items: flex-end !important; - display: flex !important; - height: 100% !important; + .truncate-expand-controls { + align-items: flex-end; + display: flex; + height: 100%; .expand-trigger { background: var(--kui-color-background-transparent, $kui-color-background-transparent); border: 0; border-radius: var(--kui-border-radius-round, $kui-border-radius-round); color: var(--kui-color-text-primary, $kui-color-text-primary); + font-family: var(--kui-font-family-text, $kui-font-family-text); font-size: var(--kui-font-size-10, $kui-font-size-10); font-weight: var(--kui-font-weight-semibold, $kui-font-weight-semibold); + line-height: var(--kui-line-height-10, $kui-line-height-10); padding: var(--kui-space-10, $kui-space-10); &:focus, &:active { @@ -282,7 +287,10 @@ onUnmounted(() => { .collapse-trigger { background-color: var(--kui-color-background-primary-weakest, $kui-color-background-primary-weakest); border-radius: var(--kui-border-radius-round, $kui-border-radius-round); + color: var(--kui-color-text-primary, $kui-color-text-primary); cursor: pointer; + outline: none; + padding: var(--kui-space-20, $kui-space-20); &:focus-visible { box-shadow: var(--kui-shadow-focus, $kui-shadow-focus); @@ -290,14 +298,17 @@ onUnmounted(() => { &:hover { background-color: var(--kui-color-background-primary-weaker, $kui-color-background-primary-weaker); + color: var(--kui-color-text-primary-strong, $kui-color-text-primary-strong) !important; } - &:focus { + &:focus, + &:focus-within { background-color: var(--kui-color-background-primary-weak, $kui-color-background-primary-weak); + color: var(--kui-color-text-primary-stronger, $kui-color-text-primary-stronger) !important; } } - &.k-truncate-content { + &.truncate-content { display: flex; flex-direction: row-reverse; height: v-bind('wrapperHeight'); @@ -305,7 +316,7 @@ onUnmounted(() => { &.expanded { height: auto; } - .k-truncate-container { + .truncate-container { display: flex; flex-wrap: wrap; gap: v-bind('gap'); @@ -318,39 +329,27 @@ onUnmounted(() => { content: '+'; } } - .collapse-trigger { - padding: var(--kui-space-20, $kui-space-20); - - &:focus, &:active { - box-shadow: none; - } - - &:focus-within { - background-color: var(--kui-color-background-primary-weakest, $kui-color-background-primary-weakest); - outline: -webkit-focus-ring-color auto 1px; - } - } } - &.k-truncate-text { + &.truncate-text { display: flex; flex-direction: column; - .k-truncate-container { + .truncate-container { -webkit-box-orient: vertical; display: -webkit-box; -webkit-line-clamp: v-bind('props.rows'); overflow: hidden; } &.expanded { - .k-truncate-container { + .truncate-container { display: block; } } } - .k-truncate-collapse-controls { - margin-top: var(--kui-space-40, $kui-space-40) !important; - place-self: flex-end !important; + .truncate-collapse-controls { + margin-top: var(--kui-space-40, $kui-space-40); + place-self: flex-end; } }