Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Split action handlers with "OR" condition in accessibility behaviors @sophieH29 ([#1622](https://github.com/stardust-ui/react/pull/1622))
- Add `headerAction` slot to the `Dialog` component @mnajdova ([#1617](https://github.com/stardust-ui/react/pull/1617))
- Add `Slider` component @Bugaa92 ([#1559](https://github.com/stardust-ui/react/pull/1559))
- Add `tooltipAsLabelBehavior` accessibility behavior for `Tooltip` @sophieH29 ([#1635](https://github.com/stardust-ui/react/pull/1635))

### Fixes
- Fix `ChatMessage`'s focus border overlays `actionMenu` in Teams theme @mnajdova ([#1637](https://github.com/stardust-ui/react/pull/1637))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from 'react'

import ComponentBestPractices from 'docs/src/components/ComponentBestPractices'

const doList = [
'Use `tooltipAsLabelBehavior` if adding tooltip to icon-only button or to another visual-only element without any text, title or label.',
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

]

const DropdownBestPractices: React.FunctionComponent<{}> = () => {
return <ComponentBestPractices doList={doList} />
}

export default DropdownBestPractices
12 changes: 12 additions & 0 deletions docs/src/examples/components/Tooltip/BestPractices/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as React from 'react'

import TooltipBestPractices from '././TooltipBestPractices'
import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection'

const BestPractices = () => (
<ExampleSection title="Best Practices">
<TooltipBestPractices />
</ExampleSection>
)

export default BestPractices
2 changes: 2 additions & 0 deletions docs/src/examples/components/Tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import Types from './Types'
import Variations from './Variations'
import Usage from './Usage'
import States from './States'
import BestPractices from './BestPractices'

const TooltipExamples = () => (
<>
<BestPractices />
<Types />
<Variations />
<States />
Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export interface TooltipProps
BasicPositioningProps {
/**
* Accessibility behavior if overridden by the user.
* @default tooltipBehavior
* @available tooltipAsLabelBehavior
* */
accessibility?: Accessibility

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Accessibility } from '../../types'
import tooltipBehavior, { TooltipBehaviorProps } from './tooltipBehavior'

/**
* @specification
* Adds attribute 'role=tooltip' to 'tooltip' slot.
* Adds attribute 'aria-hidden=false' to 'tooltip' slot if 'open' property is true. Sets the attribute to 'true' otherwise.
* Adds attribute 'aria-labelledby' based on the property 'aria-labelledby' to 'trigger' slot.
* Triggers 'close' action with 'Escape' on 'trigger'.
*/
const tooltipAsLabelBehavior: Accessibility<TooltipBehaviorProps> = props => {
const behaviorData = tooltipBehavior(props)
const defaultAriaLabeledBy = getDefaultAriaLabelledBy(props)

behaviorData.attributes = {
trigger: {
'aria-labelledby': defaultAriaLabeledBy || props['aria-labelledby'],
},
tooltip: {
...behaviorData.attributes.tooltip,
id: defaultAriaLabeledBy,
},
}

return behaviorData
}

export default tooltipAsLabelBehavior

/**
* Returns the element id of the tooltip, it is used when user does not provide aria-label or
* aria-labelledby as props.
*/
const getDefaultAriaLabelledBy = (props: TooltipBehaviorProps) => {
if (props['aria-label'] || props['aria-labelledby']) {
return undefined
}
return props.contentId
}
1 change: 1 addition & 0 deletions packages/react/src/lib/accessibility/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ export { default as accordionTitleBehavior } from './Behaviors/Accordion/accordi
export { default as accordionContentBehavior } from './Behaviors/Accordion/accordionContentBehavior'
export { default as checkboxBehavior } from './Behaviors/Checkbox/checkboxBehavior'
export { default as tooltipBehavior } from './Behaviors/Tooltip/tooltipBehavior'
export { default as tooltipAsLabelBehavior } from './Behaviors/Tooltip/tooltipAsLabelBehavior'
export { default as sliderBehavior } from './Behaviors/Slider/sliderBehavior'
2 changes: 2 additions & 0 deletions packages/react/test/specs/behaviors/behavior-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
toolbarRadioGroupBehavior,
toolbarRadioGroupItemBehavior,
tooltipBehavior,
tooltipAsLabelBehavior,
} from 'src/lib/accessibility'
import { TestHelper } from './testHelper'
import definitions from './testDefinitions'
Expand Down Expand Up @@ -100,5 +101,6 @@ testHelper.addBehavior('toolbarItemBehavior', toolbarItemBehavior)
testHelper.addBehavior('toolbarRadioGroupBehavior', toolbarRadioGroupBehavior)
testHelper.addBehavior('toolbarRadioGroupItemBehavior', toolbarRadioGroupItemBehavior)
testHelper.addBehavior('tooltipBehavior', tooltipBehavior)
testHelper.addBehavior('tooltipAsLabelBehavior', tooltipAsLabelBehavior)

testHelper.run(behaviorMenuItems)