Skip to content

Commit

Permalink
chore: add indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
anubra266 committed Dec 31, 2024
1 parent c8665f1 commit 6fb5d57
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/next-ts/pages/cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default function Page() {
<div {...api.getControlProps()}>
<button {...api.getTriggerProps()}>
<span>{api.selectedItems.map((i) => i.label).join(", ") || "Select option"}</span>
{/* <span {...api.getIndicatorProps()}>▼</span> */}
<span {...api.getIndicatorProps()}></span>
</button>
<button {...api.getClearTriggerProps()}>X</button>
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/machines/cascader/src/cascader.anatomy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const anatomy = createAnatomy("cascader").parts(
"positioner",
"content",
"list",
"indicator",
"item",
"itemText",
)
Expand Down
12 changes: 12 additions & 0 deletions packages/machines/cascader/src/cascader.connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,18 @@ export function connect<T extends PropTypes, V = any>(
})
},

getIndicatorProps() {
return normalize.element({
...parts.indicator.attrs,
dir: state.context.dir,
"aria-hidden": true,
"data-state": open ? "open" : "closed",
"data-disabled": dataAttr(disabled),
"data-invalid": dataAttr(invalid),
"data-readonly": dataAttr(readOnly),
})
},

getItemProps(props) {
const itemState = getNodeState(props)

Expand Down
1 change: 1 addition & 0 deletions packages/machines/cascader/src/cascader.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ export interface MachineApi<T extends PropTypes = PropTypes, V = TreeNode> {
getLabelProps(): T["label"]
getControlProps(): T["element"]
getTriggerProps(): T["button"]
getIndicatorProps(): T["element"]
getClearTriggerProps(): T["button"]
getPositionerProps(): T["element"]
getContentProps(): T["element"]
Expand Down

0 comments on commit 6fb5d57

Please sign in to comment.