Skip to content

feat: add titleEllipsis api #313

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions assets/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
vertical-align: top;
cursor: pointer;
}
.@{treePrefixCls}-node-content-ellipsis{
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
span {
&.@{treePrefixCls}-switcher,
&.@{treePrefixCls}-checkbox,
Expand Down
1 change: 1 addition & 0 deletions examples/basic.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class Demo extends React.Component {
<Tree
ref={this.setTreeRef}
className="myCls"
titleEllipsis
showLine
checkable
defaultExpandAll
Expand Down
25 changes: 8 additions & 17 deletions src/NodeList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ interface NodeListProps {
activeItem: FlattenNode;
focused?: boolean;
tabIndex: number;
titleEllipsis?: boolean;
checkable?: boolean;
selectable?: boolean;
disabled?: boolean;
Expand Down Expand Up @@ -121,10 +122,7 @@ function getAccessibilityPath(item: FlattenNode): string {
return path;
}

const RefNodeList: React.RefForwardingComponent<NodeListRef, NodeListProps> = (
props,
ref,
) => {
const RefNodeList: React.RefForwardingComponent<NodeListRef, NodeListProps> = (props, ref) => {
const {
prefixCls,
data,
Expand All @@ -138,6 +136,7 @@ const RefNodeList: React.RefForwardingComponent<NodeListRef, NodeListProps> = (
halfCheckedKeys,
keyEntities,
disabled,
titleEllipsis,

dragging,
dragOverNodeKey,
Expand Down Expand Up @@ -175,9 +174,7 @@ const RefNodeList: React.RefForwardingComponent<NodeListRef, NodeListProps> = (
const [prevData, setPrevData] = React.useState(data);
const [transitionData, setTransitionData] = React.useState(data);
const [transitionRange, setTransitionRange] = React.useState([]);
const [motionType, setMotionType] = React.useState<'show' | 'hide' | null>(
null,
);
const [motionType, setMotionType] = React.useState<'show' | 'hide' | null>(null);

function onMotionEnd() {
setPrevData(data);
Expand All @@ -195,9 +192,7 @@ const RefNodeList: React.RefForwardingComponent<NodeListRef, NodeListProps> = (

if (diffExpanded.key !== null) {
if (diffExpanded.add) {
const keyIndex = prevData.findIndex(
({ data: { key } }) => key === diffExpanded.key,
);
const keyIndex = prevData.findIndex(({ data: { key } }) => key === diffExpanded.key);

if (motion) setDisableVirtual(true);
const rangeNodes = getMinimumRangeTransitionRange(
Expand All @@ -213,9 +208,7 @@ const RefNodeList: React.RefForwardingComponent<NodeListRef, NodeListProps> = (
setTransitionRange(rangeNodes);
setMotionType('show');
} else {
const keyIndex = data.findIndex(
({ data: { key } }) => key === diffExpanded.key,
);
const keyIndex = data.findIndex(({ data: { key } }) => key === diffExpanded.key);

if (motion) setDisableVirtual(true);
const rangeNodes = getMinimumRangeTransitionRange(
Expand Down Expand Up @@ -303,10 +296,7 @@ const RefNodeList: React.RefForwardingComponent<NodeListRef, NodeListProps> = (
const mergedKey = getKey(key, pos);
delete restProps.children;

const treeNodeProps = getTreeNodeProps(
mergedKey,
treeNodeRequiredProps,
);
const treeNodeProps = getTreeNodeProps(mergedKey, treeNodeRequiredProps);

return (
<MotionTreeNode
Expand All @@ -318,6 +308,7 @@ const RefNodeList: React.RefForwardingComponent<NodeListRef, NodeListProps> = (
isStart={isStart}
isEnd={isEnd}
motion={motion}
titleEllipsis={titleEllipsis}
motionNodes={key === MOTION_KEY ? transitionRange : null}
motionType={motionType}
onMotionEnd={onMotionEnd}
Expand Down
5 changes: 5 additions & 0 deletions src/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface TreeProps {
style?: React.CSSProperties;
focusable?: boolean;
tabIndex?: number;
titleEllipsis?: boolean;
children?: React.ReactNode;
treeData?: DataNode[]; // Generate treeNode by children
showLine?: boolean;
Expand Down Expand Up @@ -178,6 +179,7 @@ class Tree extends React.Component<TreeProps, TreeState> {
className: PropTypes.string,
style: PropTypes.object,
tabIndex: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
titleEllipsis: PropTypes.bool,
children: PropTypes.any,
treeData: PropTypes.array, // Generate treeNode by children
showLine: PropTypes.bool,
Expand Down Expand Up @@ -222,6 +224,7 @@ class Tree extends React.Component<TreeProps, TreeState> {

static defaultProps = {
prefixCls: 'rc-tree',
titleEllipsis: false,
showLine: false,
showIcon: true,
selectable: true,
Expand Down Expand Up @@ -1038,6 +1041,7 @@ class Tree extends React.Component<TreeProps, TreeState> {
showLine,
focusable,
tabIndex = 0,
titleEllipsis,
selectable,
showIcon,
icon,
Expand Down Expand Up @@ -1112,6 +1116,7 @@ class Tree extends React.Component<TreeProps, TreeState> {
focusable={focusable}
focused={focused}
tabIndex={tabIndex}
titleEllipsis={titleEllipsis}
activeItem={this.getActiveItem()}
onFocus={this.onFocus}
onBlur={this.onBlur}
Expand Down
6 changes: 5 additions & 1 deletion src/TreeNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface TreeNodeProps {
loading?: boolean;
halfChecked?: boolean;
title?: React.ReactNode | ((data: DataNode) => React.ReactNode);
titleEllipsis?: boolean;
dragOver?: boolean;
dragOverGapTop?: boolean;
dragOverGapBottom?: boolean;
Expand Down Expand Up @@ -75,6 +76,7 @@ class InternalTreeNode extends React.Component<InternalTreeNodeProps, TreeNodeSt
loading: PropTypes.bool,
halfChecked: PropTypes.bool,
title: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
titleEllipsis: PropTypes.bool,
dragOver: PropTypes.bool,
dragOverGapTop: PropTypes.bool,
dragOverGapBottom: PropTypes.bool,
Expand Down Expand Up @@ -428,13 +430,14 @@ class InternalTreeNode extends React.Component<InternalTreeNodeProps, TreeNodeSt
// Icon + Title
renderSelector = () => {
const { dragNodeHighlight } = this.state;
const { title, selected, icon, loading, data } = this.props;
const { title, titleEllipsis, selected, icon, loading, data } = this.props;
const {
context: { prefixCls, showIcon, icon: treeIcon, draggable, loadData },
} = this.props;
const disabled = this.isDisabled();

const wrapClass = `${prefixCls}-node-content-wrapper`;
const titleEllipsisClass = `${prefixCls}-node-content-ellipsis`;

// Icon - Still show loading icon when loading without showIcon
let $icon;
Expand Down Expand Up @@ -469,6 +472,7 @@ class InternalTreeNode extends React.Component<InternalTreeNodeProps, TreeNodeSt
`${wrapClass}-${this.getNodeState() || 'normal'}`,
!disabled && (selected || dragNodeHighlight) && `${prefixCls}-node-selected`,
!disabled && draggable && 'draggable',
{ [`${titleEllipsisClass}`]: titleEllipsis },
)}
draggable={(!disabled && draggable) || undefined}
aria-grabbed={(!disabled && draggable) || undefined}
Expand Down
Loading