Skip to content

Conversation

@LFDanLu
Copy link
Member

@LFDanLu LFDanLu commented Sep 23, 2021

Closes #2328

Some known issues:

  • The tableview example with editable cells renders a bit strangely on Safari and android (the searchfield shifts when typing in it)
  • pageup/down/home/end will scroll the table when used inside a searchfield

✅ 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:

@adobe-bot
Copy link

Build successful! 🎉

…edit mode

also moved some edit mode logic out of keydowncapture in useGridCell and into useSelectableCollection so it is in a more general place
@adobe-bot
Copy link

Build successful! 🎉

Comment on lines 203 to 208
case 'Home':
if (delegate.getFirstKey) {
if (editModeEnabled) {
// Prevent scrolling from happening if in edit mode
// TODO: not sure why this doesn't stop table scrolling when in a searchfield in editmode...
e.preventDefault();
} else if (delegate.getFirstKey) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I believe this can be fixed with an approach like #1519, but will need to discuss if we want to prevent that behavior on all components that use useTextFields

Copy link
Member Author

Choose a reason for hiding this comment

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

Additionally, scrolling will still happen if the user hits home/end when the cursor is at the start/end of the input text, I figure we will want to suppress that. Open to opinions

turns out we need the stop propagation so that row selection does not happen if you click on a textfield in a editable cell for the first time
@adobe-bot
Copy link

Build successful! 🎉

Comment on lines +69 to +82
// TODO: should we support press events on textfield?
// This is added here so that pressing on a textfield in a table properly focuses the textfield
// and that selection doesn't trigger since usePress will stop propagation. However, usePress prevents default
// and thus stops text selection via mouse from working....
// let {pressProps} = usePress({
// ref
// });
// The below is an alternative that allows the user to click into a textfield in a editable cell
let onPointerDown = (e) => {
ref.current.focus();
e.stopPropagation();
};


Copy link
Member Author

Choose a reason for hiding this comment

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

Kinda iffy on this. If we don't manually focus the textfield on pointer down, clicking on a textfield in a tableview won't move focus into it. Buttons and other elements don't have this issue because they have usePress which manually focuses the element on pointer down, but we don't really want to use usePress in textfields because it will preventDefault and stop text selection via mouse.

Open to opinions on this, personally I want to have this focus behavior so that the user can do the following cases:

  • click into a textfield in a tableview without needing to activate edit mode on the cell via keyboard first (this is consistent with how other components like buttons behave in a tableview right now)
  • move focus between textfields in a tableview via clicking

Copy link
Member

Choose a reason for hiding this comment

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

Yeah this feels weird though. It's not clear you're in edit mode and can't move focus out of the cell without pressing escape. 🤔

Let's gather more opinions here.

@LFDanLu LFDanLu changed the title (WIP) Grid edit mode Grid edit mode Sep 29, 2021
@adobe-bot
Copy link

Build successful! 🎉

Copy link
Member

@devongovett devongovett left a comment

Choose a reason for hiding this comment

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

initial comments

}

let walker = getFocusableTreeWalker(ref.current);
let walker = getFocusableTreeWalker(ref.current, {tabbable: true});
Copy link
Member

Choose a reason for hiding this comment

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

We could probably use createFocusManager here? It has focusNext and focusPrevious functions which are a bit nicer to work with than tree walker.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hrm, the ArrowLeft/ArrowRight logic relies on checking if the next element is a child node or not, but createFocusManager's focusNext and focusPrevious will attempt to focus stuff immediately

state.selectionManager.setFocusedKey(node.key);
}

// Activating edit mode if user focuses a child of the editable cell (e.g. via click)
Copy link
Member

Choose a reason for hiding this comment

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

Still not sure about this one. It feels strange. You don't realize you're in edit mode at all... 🤔

let {pressProps} = usePress({...itemProps, isDisabled});

let containsEditCell = state.collection.getItem(state.editModeKey)?.parentKey === node.key;
if (containsEditCell) {
Copy link
Member

Choose a reason for hiding this comment

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

In #2363 I added an isDisabled prop to useSelectableItem which does the same thing as this. Could probably combine those.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good, I'll pull the bare minimum isDisabled changes from that PR so it doesn't break behavior here

Copy link
Member Author

Choose a reason for hiding this comment

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

Never mind, looking at it further it might be best if I wait till that PR goes in
Note to self regarding the change to be made:

  • remove the if statement and its contents
  • pass isDisabled to useSelectableItem if containsEditCell

/**
* Whether something in the collection is in edit mode and should disable typeahead and other collection keyboard behavior.
*/
editModeEnabled?: boolean
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can call this isDisabled? Not sure I want edit mode specific stuff to leak into the general useSelectableCollection since it's pretty grid specific...

Comment on lines +69 to +82
// TODO: should we support press events on textfield?
// This is added here so that pressing on a textfield in a table properly focuses the textfield
// and that selection doesn't trigger since usePress will stop propagation. However, usePress prevents default
// and thus stops text selection via mouse from working....
// let {pressProps} = usePress({
// ref
// });
// The below is an alternative that allows the user to click into a textfield in a editable cell
let onPointerDown = (e) => {
ref.current.focus();
e.stopPropagation();
};


Copy link
Member

Choose a reason for hiding this comment

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

Yeah this feels weird though. It's not clear you're in edit mode and can't move focus out of the cell without pressing escape. 🤔

Let's gather more opinions here.

}

// If there is an active editable card, make sure it remains in the DOM even when scrolled out of view
// so that we don't lose the card's focused child. This really only matters for virtualized card view
Copy link
Member

Choose a reason for hiding this comment

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

Wonder how this affects screen readers. There'd be a gap in the rows that are "visible" potentially. We should test this.

} = useFocusRing({within: true});
let {isFocusVisible, focusProps} = useFocusRing();
let {hoverProps, isHovered} = useHover({isDisabled});
let containsEditCell = state.collection.getItem(state.editModeKey)?.parentKey === item.key;
Copy link
Member Author

Choose a reason for hiding this comment

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

Note to self:
If #2363 is merged with the useSelectableItem returning isPressed, perhaps we can get rid of the usePress above in TableRow? Will need to propagate isDisabled/containsEditCell through useTableRow -> useGridRow perhaps?

@adobe-bot
Copy link

Build successful! 🎉

Comment on lines +205 to +207
// Prevent scrolling from happening if in edit mode
// TODO: not sure why this doesn't stop table scrolling when in a searchfield in editmode...
e.preventDefault();
Copy link
Member Author

@LFDanLu LFDanLu Oct 11, 2021

Choose a reason for hiding this comment

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

Can stop scrolling if we do something similar to #1519 and always prevent default on Home/End/PageUp/PageDown but we'd only want to do this if it were in a grid cell in edit mode...

Alternatively we could add Home/End/PageUp/PageDown cases to the keydown in useGridCell and prevent default if we are in edit mode but then this would disable default behavior of these keydowns on the child elements...

@LFDanLu
Copy link
Member Author

LFDanLu commented Mar 2, 2022

Closing for now, will revisit in the future

@LFDanLu LFDanLu closed this Mar 2, 2022
@LFDanLu LFDanLu deleted the issue_2328 branch January 11, 2023 01:35
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.

Grid navigation edit mode

4 participants