Skip to content

Commit

Permalink
don’t focus if target is not tab (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
vnys authored Jun 16, 2020
1 parent 47bc5bb commit 3e30c14
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
54 changes: 54 additions & 0 deletions apps/storybook-react/stories/Tabs.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,57 @@ export const tabsAndSearch = () => {
</div>
)
}

export const tabsAndInputInPanel = () => {
const [searchText, setSearchText] = useState('')
const [activeTab, setActiveTab] = useState(0)

const handleOnTextChange = (event) => {
const value = event.target.value
setSearchText(value)
}
const handleChange = (index) => {
setActiveTab(index)
}

const handleFocus = (e) => {
action('handleFocus')(e.target.textContent)
}

const handleBlur = (e) => {
action('handleBlur')(e.target.textContent)
}

return (
<div style={{ margin: '4rem' }}>
<Tabs
style={{ marginTop: '2rem' }}
activeTab={activeTab}
onChange={handleChange}
variant="fullWidth"
onFocus={handleFocus}
onBlur={handleBlur}
>
<TabList>
<Tab>Tab with textfield</Tab>
<Tab>Other tab</Tab>
</TabList>
<TabPanels>
<TabPanel style={{ maxWidth: '20em' }}>
<Typography variant="body_short" style={{ marginBottom: '1rem' }}>
Panel one
</Typography>
<Search
value={searchText}
placeholder={'Search '}
onChange={handleOnTextChange}
/>
</TabPanel>
<TabPanel>
<Typography variant="body_short">Panel two</Typography>
</TabPanel>
</TabPanels>
</Tabs>
</div>
)
}
3 changes: 3 additions & 0 deletions libraries/core-react/src/Tabs/Tabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const Tabs = forwardRef(function Tabs(
}

const handleFocus = (e) => {
if (e.target.getAttribute('role') !== 'tab') {
return
}
clearTimeout(blurTimer)
if (!tabsFocused) {
setTabsFocused(true)
Expand Down

0 comments on commit 3e30c14

Please sign in to comment.