Is it supported to use customize table cell in the table component provided by react-aria-components? #8021
Replies: 3 comments 5 replies
-
To create your own Cell, you'd need to reimplement However, I think this would be easier if you kept using our Cell, because the thing that you want to change isn't the element that is rendered. You can just wrap the children of whatever your CustomCell is. The best thing to do would be to make use of the work going on for Grid Edit Mode. Then render any extra interactive children into the cell as needed. We'll eventually have more support for Edit mode, and it'll likely extend to Table as well, but this should be enough to get you started. For a more complete list of issues associated with Edit mode, see feat: Add support for grid edit mode w/ nested interactive widgets |
Beta Was this translation helpful? Give feedback.
-
@snowystinger
Right now I'm hacking it like this import { useState } from 'react'
import { Cell as AriaCell, CellProps } from 'react-aria-components'
import Input from '../forms/Input'
import { style } from './Cell'
interface EditableCellProps extends CellProps {
initial: string | number
onChange?: (newValue: string, id: string) => void
id: string
}
export function EditableCell({
id,
initial,
onChange,
...props
}: EditableCellProps) {
const [isEditing, setIsEditing] = useState(false)
const [value, setValue] = useState(String(initial))
return (
<AriaCell css={style} {...props}>
<div
onClick={() => {
setIsEditing(true)
}}
>
{isEditing ? (
<Input
autoFocus
value={value}
onChange={(e) => setValue(e.target.value)}
onBlur={() => {
setIsEditing(false)
if (onChange && value !== String(initial)) {
onChange(value, id)
}
}}
/>
) : (
value
)}
</div>
</AriaCell>
)
} |
Beta Was this translation helpful? Give feedback.
-
We're also trying to add something as simple as |
Beta Was this translation helpful? Give feedback.
-
I want to add some editable elements such as input and provide more interactions in the table cell. So I want to customize a table cell.
Is it possible like this? And I don't know how to get the
cell
andstate
which are needed inMyTableCell
props.Beta Was this translation helpful? Give feedback.
All reactions