Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ellipsis support for accordion #159

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Release
on:
push:
branches:
- main
- main2 # Disabling for now until we can get this working (https://github.com/carbon-design-system/carbon-react-native/issues/150)
jobs:
build:
if:
Expand Down
4 changes: 2 additions & 2 deletions example/src/Views/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export default class TestAccordion extends React.Component {
<Accordion title="I am disabled" disabled={true}>
<Text text="I am the content of this accordion" />
</Accordion>
<Accordion title="I am already opened on load" open={true}>
<Accordion title="I am already opened on load and have long text" open={true}>
<Text text="I am the content of this accordion" />
<Button text="Click me to toggle the one below" onPress={() => this.setState({ openControl: !openControl })} style={styles.itemStyle} />
</Accordion>
<Accordion title="I can be controlled" open={openControl}>
<Accordion title="I can be controlled and have long text ellipsis" open={openControl} textBreakMode="tail">
<Text type={'body-01'} text="Smaller text. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." />
</Accordion>
</ScrollView>
Expand Down
11 changes: 7 additions & 4 deletions src/components/Accordion/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getColor } from '../../styles/colors';
import { createIcon, pressableFeedbackStyle, styleReferenceBreaker } from '../../helpers';
import ChevronDownIcon from '@carbon/icons/es/chevron--down/20';
import ChevronUpIcon from '@carbon/icons/es/chevron--up/20';
import { Text } from '../Text';
import { Text, TextBreakModes } from '../Text';

export type AccordionProps = {
/** Title to show for the accordion */
Expand All @@ -17,6 +17,8 @@ export type AccordionProps = {
onPress?: (value: boolean, event: GestureResponderEvent) => void;
/** Indicate if disabled */
disabled?: boolean;
/** Break mode for text. Default is to wrap text */
textBreakMode?: TextBreakModes;
/** Style to set on the item */
style?: StyleProp<ViewStyle>;
/** Direct props to set on the React Native component (including iOS and Android specific props). Most use cases should not need this. */
Expand Down Expand Up @@ -50,7 +52,7 @@ export class Accordion extends React.Component<AccordionProps> {
},
action: {
position: 'relative',
height: 48,
minHeight: 48,
padding: 13,
paddingLeft: 16,
paddingRight: 50,
Expand All @@ -61,6 +63,7 @@ export class Accordion extends React.Component<AccordionProps> {
right: 12,
},
textItem: {
flex: 1,
color: this.itemColor,
},
});
Expand Down Expand Up @@ -98,7 +101,7 @@ export class Accordion extends React.Component<AccordionProps> {
}

render(): React.ReactNode {
const { componentProps, style, disabled, title, children, firstAccordion } = this.props;
const { componentProps, style, disabled, title, children, firstAccordion, textBreakMode } = this.props;
const { open } = this.state;
const finalStyle = styleReferenceBreaker(this.styles.wrapper);

Expand All @@ -110,7 +113,7 @@ export class Accordion extends React.Component<AccordionProps> {
return (
<View style={styleReferenceBreaker(finalStyle, style)} {...(componentProps || {})}>
<Pressable style={(state) => pressableFeedbackStyle(state, this.styles.action, this.getStateStyle)} accessibilityLabel={title} accessibilityRole="togglebutton" onPress={this.toggleDropdown} disabled={disabled}>
<Text style={this.styles.textItem} text={title} />
<Text style={this.styles.textItem} text={title} breakMode={textBreakMode} />
{this.accordionIcon}
</Pressable>
{open && <View style={this.styles.content}>{children}</View>}
Expand Down