From 066c4b170850949586bf9f89370f5302a6c8f9a4 Mon Sep 17 00:00:00 2001 From: Thu Nguyen Date: Thu, 11 Jul 2024 07:27:44 -0700 Subject: [PATCH 1/6] chore: Removed Select in Preview (#2796) Fixes: #2500 We've removed the `Select` component that was in Preview. Please use the compound [`Select` component from Main](https://workday.github.io/canvas-kit/?path=/docs/components-inputs-select--basic). [category:Components] Release Note: We've removed the `Select` component that was in `@workday/canvas-kit-preview-react`. Please use the `Select` in Main (https://workday.github.io/canvas-kit/?path=/docs/components-inputs-select--basic) which is a compound component and offers more flexibility. Thank You Picture image Co-authored-by: manuel.carrera Co-authored-by: @mannycarrera4 --- cypress/integration/SelectPreview.spec.ts | 964 ------------------ modules/docs/mdx/12.0-UPGRADE-GUIDE.mdx | 23 + modules/preview-react/index.ts | 1 - modules/preview-react/select/LICENSE | 51 - modules/preview-react/select/README.md | 236 ----- modules/preview-react/select/index.ts | 8 - modules/preview-react/select/lib/Select.tsx | 595 ----------- .../preview-react/select/lib/SelectBase.tsx | 493 --------- .../preview-react/select/lib/SelectMenu.tsx | 304 ------ .../preview-react/select/lib/SelectOption.tsx | 133 --- modules/preview-react/select/lib/scrolling.ts | 42 - modules/preview-react/select/lib/types.ts | 37 - modules/preview-react/select/lib/utils.ts | 30 - .../preview-react/select/spec/SSR.spec.tsx | 18 - .../preview-react/select/spec/Select.spec.tsx | 71 -- .../preview-react/select/spec/tsconfig.json | 3 - .../preview-react/select/stories/stories.tsx | 242 ----- .../select/stories/stories_CypressTesting.tsx | 248 ----- .../select/stories/stories_visualTesting.tsx | 172 ---- .../select/stories/tsconfig.json | 3 - .../modal/stories/examples/ReturnFocus.tsx | 45 +- 21 files changed, 48 insertions(+), 3671 deletions(-) delete mode 100644 cypress/integration/SelectPreview.spec.ts create mode 100644 modules/docs/mdx/12.0-UPGRADE-GUIDE.mdx delete mode 100644 modules/preview-react/select/LICENSE delete mode 100644 modules/preview-react/select/README.md delete mode 100644 modules/preview-react/select/index.ts delete mode 100644 modules/preview-react/select/lib/Select.tsx delete mode 100644 modules/preview-react/select/lib/SelectBase.tsx delete mode 100644 modules/preview-react/select/lib/SelectMenu.tsx delete mode 100644 modules/preview-react/select/lib/SelectOption.tsx delete mode 100644 modules/preview-react/select/lib/scrolling.ts delete mode 100644 modules/preview-react/select/lib/types.ts delete mode 100644 modules/preview-react/select/lib/utils.ts delete mode 100644 modules/preview-react/select/spec/SSR.spec.tsx delete mode 100644 modules/preview-react/select/spec/Select.spec.tsx delete mode 100644 modules/preview-react/select/spec/tsconfig.json delete mode 100644 modules/preview-react/select/stories/stories.tsx delete mode 100644 modules/preview-react/select/stories/stories_CypressTesting.tsx delete mode 100644 modules/preview-react/select/stories/stories_visualTesting.tsx delete mode 100644 modules/preview-react/select/stories/tsconfig.json diff --git a/cypress/integration/SelectPreview.spec.ts b/cypress/integration/SelectPreview.spec.ts deleted file mode 100644 index 353733ceee..0000000000 --- a/cypress/integration/SelectPreview.spec.ts +++ /dev/null @@ -1,964 +0,0 @@ -import * as h from '../helpers'; - -function getAssistiveFocus($menu: JQuery): JQuery { - const activeId = $menu.attr('aria-activedescendant'); - return $menu.find(`[id="${activeId}"]`); -} - -function assertOptionInView($option: JQuery) { - const option = $option[0]; - const $menu = $option.parent(); - const menu = $menu[0]; - - const menuBorderTopWidth = parseInt($menu.css('borderTopWidth'), 10); - - const menuViewTop = menu.scrollTop + menuBorderTopWidth; - const menuViewBottom = menuViewTop + menu.clientHeight; - const optionTop = option.offsetTop; - const optionBottom = optionTop + option.offsetHeight; - - const optionInView = optionTop >= menuViewTop && optionBottom <= menuViewBottom; - - expect(optionInView).to.equal(true); -} - -function assertOptionCenteredInView($option: JQuery) { - const option = $option[0]; - const $menu = $option.parent(); - const menu = $menu[0]; - - const menuBorderTopWidth = parseInt($menu.css('borderTopWidth'), 10); - - const expectedMenuScrollTop = Math.floor( - option.offsetTop - menu.clientHeight / 2 - menuBorderTopWidth + option.clientHeight / 2 - ); - - expect(menu.scrollTop).to.equal(expectedMenuScrollTop); -} - -describe('Select', () => { - before(() => { - h.stories.visit(); - }); - ['Default', 'Alert', 'Error'].forEach(story => { - context(`given the "${story}" story is rendered`, () => { - beforeEach(() => { - h.stories.load('Preview/Select/Top Label', story); - }); - - it('should not have any axe errors', () => { - cy.checkA11y(); - }); - - context('when the select button is clicked', () => { - beforeEach(() => { - cy.findByLabelText('Label').click(); - }); - - it('should not have any axe errors', () => { - cy.checkA11y(); - }); - - context('the select button', () => { - it('should have an aria-expanded attribute set to "true"', () => { - cy.findByLabelText('Label').should('have.attr', 'aria-expanded', 'true'); - }); - }); - - context('the menu', () => { - it('should be visible', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .should('be.visible'); - }); - - it('should have focus', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .should('be.focused'); - }); - - it('should have an aria-activedescendant attribute with the same value as the id of the first option ("E-mail")', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .should($menu => { - const menuAD = $menu.attr('aria-activedescendant'); - const optionId = $menu.find(`[role=option]:eq(0)`).attr('id'); - - expect(menuAD).to.equal(optionId); - }); - }); - - it('should set assistive focus to the first option ("E-mail")', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'E-mail'); - }); - }); - - context('the first option ("Mail")', () => { - it('should have an aria-selected attribute set to "true"', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getOption(0)) - .should('have.attr', 'aria-selected', 'true'); - }); - }); - - context(`when the "Phone" option (with the value "phone") is clicked`, () => { - beforeEach(() => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getOption('Phone')) - .click(); - }); - - context('the select button', () => { - it(`should read "Phone"`, () => { - cy.findByLabelText('Label').should('have.text', 'Phone'); - }); - - it(`should have a value of "phone"`, () => { - cy.findByLabelText('Label').should('have.value', 'phone'); - }); - - it(`should re-acquire focus`, () => { - cy.findByLabelText('Label').should('be.focused'); - }); - }); - - context('the menu', () => { - it('should not be visible', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .should('not.exist'); - }); - }); - - context('when the menu is opened again', () => { - beforeEach(() => { - cy.findByLabelText('Label').click(); - }); - - context('the menu', () => { - it('should set assistive focus to the "Phone" option', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'Phone'); - }); - }); - - context('the "Phone" option', () => { - it('should have an aria-selected attribute set to "true"', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getOption('Phone')) - .should('have.attr', 'aria-selected', 'true'); - }); - }); - }); - }); - }); - - context('when the select button is focused', () => { - beforeEach(() => { - cy.findByLabelText('Label').focus(); - }); - - context('when the down arrow key is pressed', () => { - beforeEach(() => { - cy.focused().realType('{downarrow}'); - }); - - context('the select button', () => { - it('should have an aria-expanded attribute set to "true"', () => { - cy.findByLabelText('Label').should('have.attr', 'aria-expanded', 'true'); - }); - }); - - context('the menu', () => { - it('should be visible', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .should('be.visible'); - }); - - it('should have focus', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .should('be.focused'); - }); - }); - - context('when the down arrow key is pressed for a second time', () => { - beforeEach(() => { - cy.focused().realType('{downarrow}'); - }); - - context('the menu', () => { - it('should set assistive focus to the "Phone" option', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'Phone'); - }); - }); - - context('when the down arrow key is pressed for a third time', () => { - beforeEach(() => { - cy.focused().realType('{downarrow}'); - }); - - context('the menu', () => { - it('should set assistive focus to the "Mail" option', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'Mail'); - }); - }); - - context('when the enter key is pressed', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .realType('{enter}'); - }); - - context('the select button', () => { - it(`should read "Mail"`, () => { - cy.findByLabelText('Label').should('have.text', 'Mail'); - }); - - it(`should have a value of "mail"`, () => { - cy.findByLabelText('Label').should('have.value', 'mail'); - }); - - it(`should re-acquire focus`, () => { - cy.findByLabelText('Label').should('be.focused'); - }); - }); - - context('the menu', () => { - it('should not be visible', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .should('not.exist'); - }); - }); - - context('when the menu is expanded again', () => { - beforeEach(() => { - cy.focused().realType('{downarrow}'); - }); - - context('the menu', () => { - it('should set assistive focus to the "Mail" option', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'Mail'); - }); - }); - - context('the "Mail" option', () => { - it('should have an aria-selected attribute set to "true"', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getOption('Mail')) - .should('have.attr', 'aria-selected', 'true'); - }); - }); - }); - }); - }); - - context('when the up arrow key is pressed', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .realType('{uparrow}'); - }); - - context('the menu', () => { - it('should set assistive focus to the "E-mail" option', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'E-mail'); - }); - }); - }); - }); - }); - - context('when the enter key is pressed', () => { - beforeEach(() => { - cy.findByLabelText('Label').realType('{enter}'); - }); - - context('the select button', () => { - it('should have an aria-expanded attribute set to "true"', () => { - cy.findByLabelText('Label').should('have.attr', 'aria-expanded', 'true'); - }); - }); - }); - - context('when the space key is pressed', () => { - beforeEach(() => { - cy.findByLabelText('Label').type(' ', {force: true}); // disable event.preventDefault checks - }); - - context('the select button', () => { - it('should have an aria-expanded attribute set to "true"', () => { - cy.findByLabelText('Label').should('have.attr', 'aria-expanded', 'true'); - }); - }); - }); - }); - - context('when the "select" helper is used to select "Mail"', () => { - beforeEach(() => { - cy.findByLabelText('Label').pipe(h.selectPreview.select('Mail')); - }); - - it('should have a value of "mail"', () => { - cy.findByLabelText('Label').should('have.value', 'mail'); - }); - }); - - context('when the "select" helper is used to select /^Mail$/', () => { - beforeEach(() => { - cy.findByLabelText('Label').pipe(h.selectPreview.select(/^Mail$/)); - }); - - it('should have a value of "mail"', () => { - cy.findByLabelText('Label').should('have.value', 'mail'); - }); - }); - }); - }); - - context(`given the "Default" story is rendered`, () => { - beforeEach(() => { - h.stories.load('Preview/Select/Top Label', 'Default'); - }); - - context('when the menu is opened', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .focus() - .realType('{downarrow}'); - }); - - context('the menu', () => { - it('should set assistive focus to the first option ("E-mail")', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'E-mail'); - }); - }); - - context('when focus is advanced to the second option ("Phone")', () => { - beforeEach(() => { - cy.focused().realType('{downarrow}'); - }); - - context('the menu', () => { - it('should set assistive focus to the second option ("Phone")', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'Phone'); - }); - }); - - context( - 'when the menu is closed WITHOUT selecting the newly focused option ("Phone")', - () => { - beforeEach(() => { - cy.focused().realType('{esc}'); - }); - - context('when the menu is re-opened AFTER it has fully closed', () => { - beforeEach(() => { - // Wait for menu to fully close before we open it again (so we - // don't interrupt the menu's closing animation and cause it to - // re-open while it's in the middle of closing) - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .should('not.exist'); - cy.findByLabelText('Label') - .focus() - .realType('{downarrow}'); - }); - - context('the menu', () => { - it('should have reset assistive focus to the first option ("E-mail")', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'E-mail'); - }); - }); - }); - - context('when the menu is re-opened BEFORE it has fully closed', () => { - beforeEach(() => { - cy.focused().realType('{downarrow}'); - }); - - context('the menu', () => { - it('should still have assistive focus set to the second option ("Phone")', () => { - // Focus is shifting between the button and menu as we close - // and open the menu. It's important that we use getMenu rather - // than cy.focused() to ensure we obtain a reference to the menu. - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'Phone'); - }); - }); - }); - } - ); - }); - }); - }); - - context(`given the "Disabled" story is rendered`, () => { - beforeEach(() => { - h.stories.load('Preview/Select/Top Label', 'Disabled'); - }); - - it('should not have any axe errors', () => { - cy.checkA11y(); - }); - - context('the select button', () => { - it('should be disabled', () => { - cy.findByLabelText('Label').should('be.disabled'); - }); - }); - }); - - context('given the "Disabled Options Test" story is rendered', () => { - beforeEach(() => { - h.stories.load('Testing/Preview/Select/Cypress', 'Disabled Options Test'); - }); - - context('when the menu is opened', () => { - beforeEach(() => { - cy.findByLabelText('Label (Disabled Options)') - .focus() - .realType('{downarrow}'); - }); - - context('the "Carrier Pigeon" option', () => { - it('should have an aria-disabled attribute set to "true"', () => { - cy.findByLabelText('Label (Disabled Options)') - .pipe(h.selectPreview.getOption('Carrier Pigeon')) - .should('have.attr', 'aria-disabled', 'true'); - }); - }); - - context('when the down arrow key is pressed', () => { - beforeEach(() => { - cy.focused().realType('{downarrow}'); - }); - - context('the menu', () => { - it('should set assistive focus to first enabled option ("E-mail")', () => { - cy.findByLabelText('Label (Disabled Options)') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'E-mail'); - }); - }); - - context('when the up arrow key is pressed', () => { - beforeEach(() => { - cy.focused().realType('{uparrow}'); - }); - - context('the menu', () => { - it('should retain assistive focus on the "E-mail" option since the previous option ("Carrier Pigeon", which also happens to be the first option) is disabled', () => { - cy.findByLabelText('Label (Disabled Options)') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'E-mail'); - }); - }); - }); - - context('when the down arrow key is pressed 2 more times', () => { - beforeEach(() => { - cy.focused().realType('{downarrow}{downarrow}'); - }); - - context('the menu', () => { - it('should set assistive focus to the third option down ("Mail") since focus will have skipped one disabled option ("Fax")', () => { - cy.findByLabelText('Label (Disabled Options)') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'Mail'); - }); - }); - - context('when the down arrow key is pressed 2 more times', () => { - beforeEach(() => { - cy.focused().realType('{downarrow}{downarrow}'); - }); - - context('the menu', () => { - it('should set assistive focus to the first option down ("Mobile Phone") since the second option down ("Telegram", which also happens to be the last option) is disabled', () => { - cy.findByLabelText('Label (Disabled Options)') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'Mobile Phone'); - }); - }); - }); - }); - }); - - context('when the Home key is pressed', () => { - beforeEach(() => { - cy.focused().realType('{home}'); - }); - - context('the menu', () => { - it('should set assistive focus to the first enabled option ("E-mail")', () => { - cy.findByLabelText('Label (Disabled Options)') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'E-mail'); - }); - }); - }); - - context('when the End key is pressed', () => { - beforeEach(() => { - cy.focused().realType('{end}'); - }); - - context('the menu', () => { - it('should set assistive focus to the last enabled option ("Mobile Phone")', () => { - cy.findByLabelText('Label (Disabled Options)') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'Mobile Phone'); - }); - }); - }); - }); - }); - - context(`given the "Scrollable" story is rendered`, () => { - beforeEach(() => { - h.stories.load('Preview/Select/Top Label', 'Scrollable'); - }); - - context('when the select button is focused', () => { - beforeEach(() => { - cy.findByLabelText('Label').focus(); - }); - - context( - 'when a character is typed (provided no other characters have been typed in the last 500ms), the select should select the first matching option beyond the currently selected option (cycling back to the beginning of the options if necessary)', - () => { - context('when "s" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label').realType('s'); - }); - - context('the select button', () => { - it('should read the first option beginning with "s" ("San Francisco (United States)")', () => { - cy.findByLabelText('Label').should('have.text', 'San Francisco (United States)'); - }); - - it(`should have a value of "san-francisco"`, () => { - cy.findByLabelText('Label').should('have.value', 'san-francisco'); - }); - }); - }); - - context('when "s{500ms delay}s" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label').realType('ss', {delay: 500}); - }); - - context('the select button', () => { - it('should read the second option beginning with "s" ("San Mateo (United States)")', () => { - cy.findByLabelText('Label').should('have.text', 'San Mateo (United States)'); - }); - }); - }); - - context('when "s{500ms delay}d" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label').realType('sd', {delay: 500}); - }); - - context('the select button', () => { - it('should read the first option beginning with "d" ("Dallas (United States)")', () => { - cy.findByLabelText('Label').should('have.text', 'Dallas (United States)'); - }); - }); - }); - } - ); - - context( - 'when multiple characters are typed in rapid succession (<500ms between keystrokes), thus forming a string, and multiple options begin with that string, the select should retain the currently selected option for as long as possible (instead of cycling selection between matching options with each keystroke)', - () => { - context('when "sa" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label').realType('sa'); - }); - - context('the select button', () => { - it('should read "San Francisco (United States)"', () => { - cy.findByLabelText('Label').should('have.text', 'San Francisco (United States)'); - }); - }); - }); - - context('when "san " is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label').realType('san '); - }); - - context('the select button', () => { - it('should read "San Francisco (United States)"', () => { - cy.findByLabelText('Label').should('have.text', 'San Francisco (United States)'); - }); - }); - }); - - context('when "san m" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label').realType('san m'); - }); - - context('the select button', () => { - it('should read "San Mateo (United States)"', () => { - cy.findByLabelText('Label').should('have.text', 'San Mateo (United States)'); - }); - }); - }); - } - ); - - // TODO: Figure out why this test doesn't open the menu when the - // space key is pressed when using Firefox with Cypress (pressing - // the space key in the middle of a typeahead string in normal - // usage of Firefox opens the menu, see SelectBase) - // Ensure Firefox doesn't display the menu if there's a space in the - // typeahead string - // context('when "san " is typed', () => { - // beforeEach(() => { - // cy.findByLabelText('Label').realType('san '); - // }); - - // context('the menu', () => { - // it('should not be visible', () => { - // cy.findByLabelText('Label') - // .pipe(h.selectPreview.getMenu) - // .should('not.exist'); - // }); - // }); - // }); - }); - - context('when the menu is opened', () => { - beforeEach(() => { - cy.findByLabelText('Label').click(); - }); - - context( - 'when a character is typed (provided no other characters have been typed in the last 500ms), the select should advance assistive focus to the first matching option beyond the currently selected option (cycling back to the beginning of the options if necessary) and scroll that option into view', - () => { - context('when "s" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .realType('s'); - }); - - context('the menu', () => { - it('should set assistive focus to the first option beginning with "s" ("San Francisco (United States)")', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'San Francisco (United States)'); - }); - - it('should scroll so that the "San Francisco (United States)" option is fully visible', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should(assertOptionInView); - }); - }); - }); - - context('when "s{500ms delay}s" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .realType('ss', {delay: 500}); - }); - - context('the menu', () => { - it('should set assistive focus to the second option beginning with "s" ("San Mateo (United States)")', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'San Mateo (United States)'); - }); - - it('should scroll so that the "San Mateo (United States)" option is fully visible', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should(assertOptionInView); - }); - }); - }); - - context('when "s{500ms delay}d" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .realType('sd', {delay: 500}); - }); - - context('the menu', () => { - it('should set assistive focus to the first option beginning with "d" ("Dallas (United States)")', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'Dallas (United States)'); - }); - - it('should scroll so that the "Dallas (United States)" option is fully visible', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should(assertOptionInView); - }); - }); - }); - - context('when "the onto" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .realType('the onto'); - }); - - context('the menu', () => { - it('should set assistive focus to "The Ontologically..."', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should( - 'have.text', - 'The Ontologically Anthropocentric Sensory Immersive Simulation (Virtual Reality)' - ); - }); - - it('should scroll so that the "The Ontologically..." (text wrapped) option is fully visible', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should(assertOptionInView); - }); - }); - }); - } - ); - - context( - 'when multiple characters are typed in rapid succession (<500ms between keystrokes), thus forming a string, and multiple options begin with that string, the select should retain assistive focus on the currently focused option for as long as possible (instead of cycling focus between matching options with each keystroke)', - () => { - context('when "sa" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .realType('sa'); - }); - - context('the menu', () => { - it('should set assistive focus to the "San Francisco (United States)" option', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'San Francisco (United States)'); - }); - }); - }); - - context('when "san " is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .realType('san '); - }); - - context('the menu', () => { - it('should set assistive focus to the "San Francisco (United States)" option', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'San Francisco (United States)'); - }); - }); - }); - - context('when "san m" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .realType('san m'); - }); - - context('the menu', () => { - it('should set assistive focus to the "San Mateo (United States)" option', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'San Mateo (United States)'); - }); - }); - }); - } - ); - }); - - context( - 'when the menu is opened and the selected option is initially out of view, the menu should scroll the selected option into view and center it if possible', - () => { - context('when "Dallas (United States)" is selected and the menu is opened', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .focus() - .type('d') - .click(); - }); - - context('the menu', () => { - it('should scroll so that the "Dallas (United States)" option is centered in view', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should(assertOptionCenteredInView); - }); - }); - }); - - context( - 'when "The Ontologically..." (text wrapped) is selected and the menu is opened', - () => { - beforeEach(() => { - cy.findByLabelText('Label') - .focus() - .type('the onto') - .click(); - }); - - context('the menu', () => { - it('should scroll so that the "The Ontologically..." option is centered in view', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should(assertOptionCenteredInView); - }); - }); - } - ); - } - ); - }); - - context(`given the "Portal Test" story is rendered`, () => { - beforeEach(() => { - h.stories.load('Testing/Preview/Select/Cypress', 'Portal Test'); - }); - - context('when the page is scrolled to the bottom', () => { - beforeEach(() => { - cy.scrollTo('bottom'); - cy.window() - .its('scrollY') - .as('originalWindowScrollY'); - }); - - context('when the bottommost select button is clicked', () => { - beforeEach(() => { - cy.findByLabelText('Label (Bottom)').click(); - }); - - context('the page', () => { - it('should not scroll', () => { - cy.window().then($window => { - cy.get('@originalWindowScrollY').should('equal', Math.floor($window.scrollY)); - }); - }); - }); - }); - - context( - `when the blur test button is clicked and then the bottommost select button (which is re-rendered by the test button's blur handler) is clicked`, - () => { - beforeEach(() => { - cy.findByTestId('blur-test-button').click(); - cy.findByLabelText('Label (Bottom)').click(); - }); - - context('the page', () => { - it('should not scroll', () => { - cy.window().then($window => { - cy.get('@originalWindowScrollY').should('equal', Math.floor($window.scrollY)); - }); - }); - }); - } - ); - }); - }); - - context(`given the "Accessibility Test" story is rendered`, () => { - beforeEach(() => { - h.stories.load('Testing/Preview/Select/Cypress', 'Accessibility Test'); - }); - - context('when the select button with aria-required set to true is clicked', () => { - beforeEach(() => { - cy.findByLabelText(/Label \(aria-required\)/).click(); - }); - - context('the menu', () => { - it('should have an aria-required attribute set to "true"', () => { - cy.findByLabelText(/Label \(aria-required\)/) - .pipe(h.selectPreview.getMenu) - .should('have.attr', 'aria-required', 'true'); - }); - }); - }); - - context('when the select button with required set to true is clicked', () => { - beforeEach(() => { - cy.findByLabelText(/Label \(required\)/).click(); - }); - - context('the menu', () => { - it('should have an aria-required attribute set to "true"', () => { - cy.findByLabelText(/Label \(required\)/) - .pipe(h.selectPreview.getMenu) - .should('have.attr', 'aria-required', 'true'); - }); - }); - }); - }); -}); diff --git a/modules/docs/mdx/12.0-UPGRADE-GUIDE.mdx b/modules/docs/mdx/12.0-UPGRADE-GUIDE.mdx new file mode 100644 index 0000000000..b327b97fcb --- /dev/null +++ b/modules/docs/mdx/12.0-UPGRADE-GUIDE.mdx @@ -0,0 +1,23 @@ + + +# Canvas Kit 12.0 Upgrade Guide + +This guide contains an overview of the changes in Canvas Kit v12. Please +[reach out](https://github.com/Workday/canvas-kit/issues/new?labels=bug&template=bug.md) if you have +any questions. + +## Why You Should Upgrade + +## Table of contents + +- [Removals](#removals) + - [Select (Preview)](#select-preview) + +## Removals +Removals are deletions from our codebase and you can no longer consume this component. We've either promoted or replaced a component or utility. + +### Select (Preview) + +**PR:** [#2796](https://github.com/Workday/canvas-kit/pull/2796) + +We've removed the `Select` component that was in Preview. Please use the compound [`Select` component from Main](https://workday.github.io/canvas-kit/?path=/docs/components-inputs-select--basic). diff --git a/modules/preview-react/index.ts b/modules/preview-react/index.ts index 32bd20a30f..7ee2c454db 100644 --- a/modules/preview-react/index.ts +++ b/modules/preview-react/index.ts @@ -4,7 +4,6 @@ export * from './loading-sparkles'; export * from './menu'; export * from './pill'; export * from './segmented-control'; -export * from './select'; export * from './side-panel'; export * from './status-indicator'; export * from './text-area'; diff --git a/modules/preview-react/select/LICENSE b/modules/preview-react/select/LICENSE deleted file mode 100644 index 5bcbbab3b9..0000000000 --- a/modules/preview-react/select/LICENSE +++ /dev/null @@ -1,51 +0,0 @@ -Apache License, Version 2.0 Apache License Version 2.0, January 2004 - -http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. -"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. -"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. -"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. -"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. -"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. -"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. -"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). -"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. -"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. - -2. Grant of Copyright License. -Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. -Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. - -4. Redistribution. -You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: -You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. - -5. Submission of Contributions. -Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. - -6. Trademarks. -This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. -Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. -In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. -While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -©2020. Workday, Inc. All rights reserved. Workday and the Workday logo are registered trademarks of Workday, Inc. All other brand and product names are trademarks or registered trademarks of their respective holders. - -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/modules/preview-react/select/README.md b/modules/preview-react/select/README.md deleted file mode 100644 index dc196ee7e1..0000000000 --- a/modules/preview-react/select/README.md +++ /dev/null @@ -1,236 +0,0 @@ -# Canvas Kit Select (with Canvas-styled Menu) - - - PREVIEW: Beta - This component is in Preview because it has not been converted to a [Compound Component](../../docs/mdx/COMPOUND_COMPONENTS.mdx) yet. - -A Canvas-styled Select with a Canvas-styled menu. This is a -[_controlled_](https://reactjs.org/docs/forms.html#controlled-components) component. - -Undocumented props (`disabled`, `name`, etc.) should behave similarly to how you would expect from a -standard `; -} -``` - -#### Accessible Example - -```tsx -import * as React from 'react'; -import {Select} from '@workday/canvas-kit-preview-react/select'; -import {FormField} from '@workday/canvas-kit-react/form-field'; - -function Example() { - const options = [ - {label: 'E-mail', value: 'email'}, - {label: 'Phone', value: 'phone'}, - {label: 'Fax (disabled)', value: 'fax', disabled: true}, - {label: 'Mail', value: 'mail'}, - ]; - - const [value, setValue] = React.useState('email'); - - const handleChange = event => { - setValue(event.currentTarget.value); - }; - - return ( - - - - ); -} -``` - -#### Example with Custom Options Data - -Each option in `options` may contain a `data` object with any number of key/value pairs. This `data` -object is carried over to the `option` passed into the `renderOption` function where it may then be -used to customize how each option is rendered. - -```tsx -import * as React from 'react'; -import {Select} from '@workday/canvas-kit-preview-react/select'; -import {FormField} from '@workday/canvas-kit-react/form-field'; -import {colors, typeColors} from '@workday/canvas-kit-react/tokens'; -import { - activityStreamIcon, - avatarIcon, - uploadCloudIcon, - userIcon, -} from '@workday/canvas-system-icons-web'; -import {SystemIcon} from '@workday/canvas-kit-react/icon'; - -function Example() { - const options = [ - {value: 'Activity Stream', data: {icon: activityStreamIcon}}, - {value: 'Avatar', data: {icon: avatarIcon}}, - {value: 'Upload Cloud', data: {icon: uploadCloudIcon}}, - {value: 'User', data: {icon: userIcon}}, - ]; - - const renderOption = option => { - const iconColor = option.focused ? typeColors.inverse : colors.blackPepper100; - return ( -
- -
{option.value}
-
- ); - }; - - const [value, setValue] = React.useState('Activity Stream'); - - const handleChange = event => { - setValue(event.currentTarget.value); - }; - - return ( - - -``` - -## Component Props - -### Required - -#### `options: (Option | string)[]` - -> The options of the Select. `options` may be an array of objects or an array of strings. -> -> If `options` is an array of objects, each object must adhere to the `Option` interface: -> -> - `data: object` (optional) -> - `disabled: boolean` (optional) -> - `id: string` (optional, a random `id` will be assigned to the object if one isn't provided) -> - `label: string` (optional, analagous to the text content of an `