-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into mayank/displaycontents-voiceover
- Loading branch information
Showing
8 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
title: MiddleTextTruncation | ||
description: A utility component for truncating long texts in the middle. | ||
thumbnail: #TODO | ||
group: utilities | ||
--- | ||
|
||
<p>{frontmatter.description}</p> | ||
|
||
## Usage | ||
|
||
When displaying texts with constrains on its width, the `MiddleTextTruncation` component can help by truncating long texts in the middle with an ellipsis (`"…"`). This ensures that the beginning and the end of the text remain visible. | ||
|
||
<LiveExample src='MiddleTextTruncation.main.jsx' truncated={false}> | ||
<AllExamples.MiddleTextTruncationMainExample client:load /> | ||
</LiveExample> | ||
|
||
For more examples, see [truncation in Select](/docs/select#truncation). | ||
|
||
### Number of end characters | ||
|
||
By default, six characters are left visible at the end of the truncated text. This ensures that important suffixes, such as file extensions or identifiers, remain visible. This number can be modified through the `endCharsCount` prop to suit user's specific needs. | ||
|
||
<LiveExample src='MiddleTextTruncation.endCharsCount.jsx'> | ||
<AllExamples.MiddleTextTruncationEndCharsCountExample client:load /> | ||
</LiveExample> | ||
|
||
### Customization | ||
|
||
For further control over the rendering of the content, the `textRenderer` prop allows users to provide a custom rendering function. This function takes `originalText` and `truncatedText` as parameters and returns a `ReactNode`. | ||
|
||
<LiveExample src='MiddleTextTruncation.customizeTruncation.jsx'> | ||
<AllExamples.MiddleTextTruncationCustomizationExample client:load /> | ||
</LiveExample> | ||
|
||
## Accessibility | ||
|
||
This component only truncates the content visually but leaves the full content in the accessibility tree. That way, users using assistive technologies can still have access to the full content. This is also consistent with the browser's default `text-overflow` behavior. | ||
|
||
However, this behavior may cause some inconvenience for screen-reader users, as the accessible text can become overly verbose. Thus, we recommend taking this into consideration when planning the UX. | ||
|
||
## Props | ||
|
||
<PropsTable path='@itwin/itwinui-react/esm/utils/components/MiddleTextTruncation.d.ts' /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.demo-container { | ||
width: 300px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import * as React from 'react'; | ||
import { MiddleTextTruncation } from '@itwin/itwinui-react'; | ||
|
||
export default () => { | ||
return ( | ||
<MiddleTextTruncation | ||
className='demo-container' | ||
text='MyTitleWithAReallyLongNameThatWillBeTruncatedWithCustomizedStylingBecauseItIsReallyThatLongSoHardToBelieve' | ||
textRenderer={(truncatedText) => <b>{truncatedText}</b>} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.demo-container { | ||
width: 300px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import * as React from 'react'; | ||
import { MiddleTextTruncation } from '@itwin/itwinui-react'; | ||
|
||
export default () => { | ||
return ( | ||
<MiddleTextTruncation | ||
className='demo-container' | ||
endCharsCount={15} | ||
text={ | ||
'ThisIsMyVeryLongFileNameWithImportantExtension_FinalVersion_V2.docx' | ||
} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.demo-container { | ||
width: 300px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import * as React from 'react'; | ||
import { MiddleTextTruncation } from '@itwin/itwinui-react'; | ||
|
||
export default () => { | ||
return ( | ||
<MiddleTextTruncation | ||
className='demo-container' | ||
text='MyTitleWithAReallyLongNameThatWillBeTruncatedBecauseItIsReallyThatLongSoHardToBelieve' | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters