Skip to content

Conversation

LFDanLu
Copy link
Member

@LFDanLu LFDanLu commented Apr 14, 2021

Closes #1706

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

LFDanLu added 5 commits April 5, 2021 09:46
still need to figure out a good way to not prevent default for mouse down in useSelectableCollection
…ar in the Table

there is an area just above the scroll bar where the click target is the Table collection where we need to stop focus from moving to the collection so scroll jumping does not happen
@LFDanLu LFDanLu changed the title (WIP) Support text selection in Tables without row selection Support text selection in Tables without row selection Apr 14, 2021
@LFDanLu LFDanLu marked this pull request as ready for review April 14, 2021 21:55
@adobe-bot
Copy link

Build successful! 🎉

Comment on lines 363 to 366
// e.target.parentElement check is for Table since the scrollbar click occurs on the Table body
if (e.target.parentElement === ref.current || e.target === ref.current) {
e.preventDefault();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit iffy about this since it prevents text selection on a the collection's immediate child element (e.g. imagine that the Table body was just a div with text)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move the table specific case into table so it doesn't apply to other components.

@adobe-bot
Copy link

Build successful! 🎉

@@ -27,7 +27,8 @@ export interface GridRowProps<T> {
}

export interface GridRowAria {
rowProps: HTMLAttributes<HTMLElement>
rowProps: HTMLAttributes<HTMLElement>,
isPressed: boolean
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer not to expose this

@@ -524,10 +525,11 @@ function TableRow({item, children, ...otherProps}) {
styles,
'spectrum-Table-row',
{
'is-active': isPressed && allowsSelection,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it would be better to add a separate usePress within the TableRow component rather than returning isPressed through all of these hooks.

Comment on lines 363 to 366
// e.target.parentElement check is for Table since the scrollbar click occurs on the Table body
if (e.target.parentElement === ref.current || e.target === ref.current) {
e.preventDefault();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move the table specific case into table so it doesn't apply to other components.


// Get rid of click/drag/pointer/mousedown handlers if selection isn't allowed so that text selection can happen
if (!allowsSelection) {
pressProps = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is relying on some implementation details of usePress. Maybe it would be better to pass through everything from itemProps except for onPress?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure I'm on the same page: this is suggesting that I modify itemProps if !allowSelection such that it doesn't have onPress/onPressStart/onPressUp when it gets passed to usePress correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so, usePress still returns onPointerDown/onClick/etc and those handlers do things like preventDefault and disableTextSelection which stop text selection from happening

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would setting isDisabled on usePress when allowsSelection is false work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately that doesn't work without modifications to usePress. If I change the following lines in usePress so that they early return if isDisabled then this appraoch will work, but I'm unsure what ramifications that would have on overall usePress behavior

https://github.com/adobe/react-spectrum/blob/main/packages/@react-aria/interactions/src/usePress.ts#L283
https://github.com/adobe/react-spectrum/blob/main/packages/@react-aria/interactions/src/usePress.ts#L318

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's what I thought. That's why I originally suggested doing something like this:

if (!allowsSelection) {
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  let {onPressStart, onPressEnd, onPressUp, onPress, ...otherProps} = itemProps;
  pressProps = otherProps;
}

We basically don't want to use the pressProps at all in that case, but only the other item props. I feel like this is less reliant on implementation details from usePress and useSelectableItem than specifically copying over certain DOM props. If either of those hooks changed in the future to add additional props the current solution would break.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, I misunderstood this earlier. Yeah this should work, I'll update

@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

@@ -203,6 +204,16 @@ export function useGridCell<T, C extends GridCollection<T>>(props: GridCellProps
});
};

// Get rid of click/drag/pointer/mousedown handlers if selection isn't allowed so that text selection can happen
if (!allowsSelection) {
pressProps = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think you need to update this one as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah derp, thanks for catching

@adobe-bot
Copy link

Build successful! 🎉

@devongovett devongovett merged commit 2cb4649 into main Apr 20, 2021
@devongovett devongovett deleted the issue_1706 branch April 20, 2021 22:00
majornista pushed a commit to majornista/react-spectrum-v3 that referenced this pull request May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Non selectable table updates
3 participants