Skip to content

Commit

Permalink
bugfix(react-tag-picker): ensures input behaviour on text selection (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bsunderhus committed Aug 21, 2024
1 parent 9c8b306 commit 843386f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "bugfix: ensures input behaviour on text selection",
"packageName": "@fluentui/react-tag-picker",
"email": "bernardo.sunderhus@gmail.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -302,17 +302,43 @@ describe('TagPicker', () => {
cy.get(`[data-testid="tag--${options[0]}"]`).focus().realPress('Backspace').should('not.exist');
cy.get(`[data-testid="tag--${options[1]}"]`).should('be.focused');
});
it('should move to last tag on Backspace key press on input', () => {
mount(<TagPickerControlled defaultSelectedOptions={options} />);
cy.get('[data-testid="tag-picker-input"]').focus().realPress('Backspace');
cy.get(`[data-testid="tag--${options[options.length - 1]}"]`).should('be.focused');
});

it('should focus on input once all tags have been removed', () => {
mount(<TagPickerControlled defaultSelectedOptions={[options[0]]} />);
cy.get(`[data-testid="tag--${options[0]}"]`).focus().realPress('Backspace').should('not.exist');
cy.get('[data-testid="tag-picker-input"]').should('be.focused');
});
});
describe('input', () => {
it('should move to last tag on Backspace key press on input, when input is empty', () => {
mount(<TagPickerControlled defaultSelectedOptions={options} />);
cy.get('[data-testid="tag-picker-input"]').focus().realPress('Backspace');
cy.get(`[data-testid="tag--${options[options.length - 1]}"]`).should('be.focused');
});
it('should delete input content on Backspace when input is not empty', () => {
mount(<TagPickerControlled defaultSelectedOptions={options} />);
cy.get('[data-testid="tag-picker-input"]').focus().realType('Some Text').realPress('Backspace');
cy.get(`[data-testid="tag--${options[options.length - 1]}"]`).should('not.be.focused');
cy.get('[data-testid="tag-picker-input"]').should('have.value', 'Some Tex').should('be.focused');
});
it('should move to last tag on Backspace key press on input, when input is not empty but the cursor is on the first character', () => {
mount(<TagPickerControlled defaultSelectedOptions={options} />);
cy.get('[data-testid="tag-picker-input"]').focus().realType('SomeText').realPress('Backspace');
cy.get(`[data-testid="tag--${options[options.length - 1]}"]`).should('not.be.focused');
cy.get('[data-testid="tag-picker-input"]').should('have.value', 'SomeTex').should('be.focused');
cy.get('[data-testid="tag-picker-input"]').realPress(['ControlLeft', 'ArrowLeft']).realPress('Backspace');
cy.get(`[data-testid="tag--${options[options.length - 1]}"]`).should('be.focused');
});
it('should delete input content on Backspace when input is not empty and selected', () => {
mount(<TagPickerControlled defaultSelectedOptions={options} />);
cy.get('[data-testid="tag-picker-input"]').focus().realType('SomeText').realPress('Backspace');
cy.get(`[data-testid="tag--${options[options.length - 1]}"]`).should('not.be.focused');
cy.get('[data-testid="tag-picker-input"]').should('have.value', 'SomeTex').should('be.focused');
cy.get('[data-testid="tag-picker-input"]').realPress(['ControlLeft', 'A']).realPress('Backspace');
cy.get(`[data-testid="tag--${options[options.length - 1]}"]`).should('not.be.focused');
cy.get('[data-testid="tag-picker-input"]').should('have.value', '').should('be.focused');
});
});
});
it('should not render popover when "noPopover"', () => {
mount(<TagPickerControlled noPopover />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const useTagPickerInput_unstable = (
if (
(event.key === ArrowLeft || event.key === Backspace) &&
event.currentTarget.selectionStart === 0 &&
event.currentTarget.selectionEnd === 0 &&
tagPickerGroupRef.current
) {
findLastFocusable(tagPickerGroupRef.current)?.focus();
Expand Down

0 comments on commit 843386f

Please sign in to comment.