From 519154721a3a423fc7b7cc5a6885790ec82cf55c Mon Sep 17 00:00:00 2001 From: cchaos Date: Wed, 19 Jun 2019 14:34:25 -0400 Subject: [PATCH] Added `autoFocus` option to `EuiTabbedContent` --- src-docs/src/views/tabs/tabbed_content.js | 1 + .../date_popover/date_popover_content.js | 1 + src/components/tabs/index.d.ts | 3 ++ .../__snapshots__/tabbed_content.test.js.snap | 6 ++- .../tabs/tabbed_content/tabbed_content.js | 50 +++++++++++++++++-- 5 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src-docs/src/views/tabs/tabbed_content.js b/src-docs/src/views/tabs/tabbed_content.js index b54f309d519c..acb7746c754f 100644 --- a/src-docs/src/views/tabs/tabbed_content.js +++ b/src-docs/src/views/tabs/tabbed_content.js @@ -91,6 +91,7 @@ class EuiTabsExample extends Component { { console.log('clicked tab', tab); }} diff --git a/src/components/date_picker/super_date_picker/date_popover/date_popover_content.js b/src/components/date_picker/super_date_picker/date_popover/date_popover_content.js index a6ed6026fad3..79629bd5323e 100644 --- a/src/components/date_picker/super_date_picker/date_popover/date_popover_content.js +++ b/src/components/date_picker/super_date_picker/date_popover/date_popover_content.js @@ -91,6 +91,7 @@ export function EuiDatePopoverContent({ void; @@ -37,6 +39,7 @@ declare module '@elastic/eui' { size?: TAB_SIZES; display?: TAB_DISPLAYS; expand?: boolean; + autoFocus?: TABBED_CONTENT_AUTOFOCUS; } export const EuiTab: FunctionComponent< diff --git a/src/components/tabs/tabbed_content/__snapshots__/tabbed_content.test.js.snap b/src/components/tabs/tabbed_content/__snapshots__/tabbed_content.test.js.snap index e0d0cd2da8a6..2fc0b3a41245 100644 --- a/src/components/tabs/tabbed_content/__snapshots__/tabbed_content.test.js.snap +++ b/src/components/tabs/tabbed_content/__snapshots__/tabbed_content.test.js.snap @@ -50,6 +50,7 @@ exports[`EuiTabbedContent behavior when selected tab state isn't controlled by t exports[`EuiTabbedContent behavior when uncontrolled, the selected tab should update if it receives new content 1`] = ` -
+
{ + console.log('THE FOCUS HAPPENED', this.state.inFocus, this.props.autoFocus); + + if (!this.state.inFocus && this.props.autoFocus === 'selected') { + console.log('Focusing tab'); + document.getElementById(this.state.selectedTabId).focus(); + } + + this.setState({ + inFocus: true, + }); + }; + + removeFocus = () => { + this.setState({ + inFocus: false, + }); + }; + onTabClick = selectedTab => { const { onTabClick, selectedTab: externalSelectedTab } = this.props; @@ -82,6 +113,7 @@ export class EuiTabbedContent extends Component { selectedTab: externalSelectedTab, size, tabs, + autoFocus, ...rest } = this.props; @@ -93,7 +125,11 @@ export class EuiTabbedContent extends Component { const { content: selectedTabContent, id: selectedTabId } = selectedTab; return ( -
+
{tabs.map(tab => { const { @@ -125,3 +161,7 @@ export class EuiTabbedContent extends Component { ); } } + +EuiTabbedContent.defaultProps = { + autoFocus: 'initial', +};