|
| 1 | +--- |
| 2 | +title: 'Focusable' |
| 3 | +section: components |
| 4 | +cssPrefix: 'pf-c-focusable' |
| 5 | +typescript: true |
| 6 | +propComponents: ['Focusable'] |
| 7 | +--- |
| 8 | + |
| 9 | +import { Focusable, Button, Tooltip, Radio, Card, CardHeader, CardBody, CardFooter } from '@patternfly/react-core'; |
| 10 | +import { BeerIcon } from '@patternfly/react-icons'; |
| 11 | + |
| 12 | +## Examples |
| 13 | +```js title=Focus-text |
| 14 | +import React from 'react'; |
| 15 | +import { Focusable } from '@patternfly/react-core'; |
| 16 | + |
| 17 | +class FocusableText extends React.Component { |
| 18 | + constructor(props) { |
| 19 | + super(props); |
| 20 | + } |
| 21 | + render() { |
| 22 | + return ( |
| 23 | + <Focusable> |
| 24 | + This text is focusable |
| 25 | + </Focusable> |
| 26 | + ); |
| 27 | + } |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +```js title=Focus-non-interactive-html-children |
| 32 | +import React from 'react'; |
| 33 | +import { Focusable, Button } from '@patternfly/react-core'; |
| 34 | + |
| 35 | +class FocusNonInteractiveHtmlChildren extends React.Component { |
| 36 | + constructor(props) { |
| 37 | + super(props); |
| 38 | + } |
| 39 | + render() { |
| 40 | + return ( |
| 41 | + <Focusable aria-label="Example focusable article"> |
| 42 | + <article>Article element</article> |
| 43 | + </Focusable> |
| 44 | + ); |
| 45 | + } |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +```js title=Focus-non-interactive-component-children |
| 50 | +import React from 'react'; |
| 51 | +import { Focusable, Button, Card, CardHeader, CardBody, CardFooter } from '@patternfly/react-core'; |
| 52 | + |
| 53 | +class FocusNonInteractiveComponentChildren extends React.Component { |
| 54 | + constructor(props) { |
| 55 | + super(props); |
| 56 | + } |
| 57 | + render() { |
| 58 | + return ( |
| 59 | + <Focusable> |
| 60 | + <Card> |
| 61 | + <CardHeader>Header</CardHeader> |
| 62 | + <CardBody>Body</CardBody> |
| 63 | + <CardFooter>Footer</CardFooter> |
| 64 | + </Card> |
| 65 | + </Focusable> |
| 66 | + ); |
| 67 | + } |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +```js title=Focus-with-positive-tabindex |
| 72 | +import React from 'react'; |
| 73 | +import { Focusable } from '@patternfly/react-core'; |
| 74 | + |
| 75 | +class FocusPositiveTabindex extends React.Component { |
| 76 | + constructor(props) { |
| 77 | + super(props); |
| 78 | + } |
| 79 | + render() { |
| 80 | + return ( |
| 81 | + <Focusable tabIndex={1}> |
| 82 | + <button className="pf-c-button pf-m-tertiary">First focusable element on the page (example)</button> |
| 83 | + </Focusable> |
| 84 | + ); |
| 85 | + } |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +```js title=Focus-an-icon |
| 90 | +import React from 'react'; |
| 91 | +import { Focusable, Button, Tooltip } from '@patternfly/react-core'; |
| 92 | +import { BeerIcon } from '@patternfly/react-icons'; |
| 93 | + |
| 94 | +class FocusIcon extends React.Component { |
| 95 | + constructor(props) { |
| 96 | + super(props); |
| 97 | + } |
| 98 | + render() { |
| 99 | + return ( |
| 100 | + <Tooltip content="Focus on beer"> |
| 101 | + <Focusable> |
| 102 | + <BeerIcon /> |
| 103 | + </Focusable> |
| 104 | + </Tooltip> |
| 105 | + ); |
| 106 | + } |
| 107 | +} |
| 108 | +``` |
| 109 | + |
| 110 | +```js title=Wrapping-disabled-button-with-tooltip |
| 111 | +import React from 'react'; |
| 112 | +import { Focusable, Button, Tooltip } from '@patternfly/react-core'; |
| 113 | + |
| 114 | +class WrapDisabledButtonTooltip extends React.Component { |
| 115 | + constructor(props) { |
| 116 | + super(props); |
| 117 | + } |
| 118 | + |
| 119 | + render() { |
| 120 | + return ( |
| 121 | + <Tooltip content="Disabled button tooltip content"> |
| 122 | + <Focusable withContainer component="span"> |
| 123 | + <Button isDisabled onClick={() => {console.log('click event fired for disabled button')}}>Disabled button text</Button> |
| 124 | + </Focusable> |
| 125 | + </Tooltip> |
| 126 | + ); |
| 127 | + } |
| 128 | +} |
| 129 | +``` |
| 130 | + |
| 131 | +```js title=Wrapping-disabled-html-button-with-tooltip |
| 132 | +import React from 'react'; |
| 133 | +import { Focusable, Button, Tooltip } from '@patternfly/react-core'; |
| 134 | + |
| 135 | +class WrapDisabledButtonTooltip extends React.Component { |
| 136 | + constructor(props) { |
| 137 | + super(props); |
| 138 | + } |
| 139 | + |
| 140 | + render() { |
| 141 | + return ( |
| 142 | + <Tooltip content="Disabled button tooltip content"> |
| 143 | + <Focusable withContainer component="span"> |
| 144 | + <button disabled onClick={() => {console.log('click event fired for html disabled button')}}>Disabled button text</button> |
| 145 | + </Focusable> |
| 146 | + </Tooltip> |
| 147 | + ); |
| 148 | + } |
| 149 | +} |
| 150 | +``` |
| 151 | + |
| 152 | +```js title=Wrapping-disabled-radio-with-tooltip |
| 153 | +import React from 'react'; |
| 154 | +import { Focusable, Radio, Tooltip } from '@patternfly/react-core'; |
| 155 | + |
| 156 | +class WrapDisabledRadioTooltip extends React.Component { |
| 157 | + constructor(props) { |
| 158 | + super(props); |
| 159 | + } |
| 160 | + render() { |
| 161 | + return ( |
| 162 | + <Tooltip content="Disabled radio tooltip content"> |
| 163 | + <Focusable withContainer> |
| 164 | + <Radio isDisabled label="Disabled radio with tooltip" id="disabled-radio-with-tooltip" name="radio-1" /> |
| 165 | + </Focusable> |
| 166 | + </Tooltip> |
| 167 | + ); |
| 168 | + } |
| 169 | +} |
| 170 | +``` |
0 commit comments