-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fabric component: revert class change and make it backwards compatible (
#4671) * Making the Fabric component backwards compatible. Fixing the missing export. * Adding change files and cleanup. * Removing whitespace.
- Loading branch information
Showing
12 changed files
with
143 additions
and
20 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
common/changes/@uifabric/utilities/fix-fabric-isfocusvisible_2018-04-25-01-59.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@uifabric/utilities", | ||
"comment": "Adding `isDirectionalKeyCode` helper.", | ||
"type": "minor" | ||
} | ||
], | ||
"packageName": "@uifabric/utilities", | ||
"email": "[email protected]" | ||
} |
11 changes: 11 additions & 0 deletions
11
common/changes/office-ui-fabric-react/fix-fabric-isfocusvisible_2018-04-25-01-59.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "office-ui-fabric-react", | ||
"comment": "Fabric: the isFocusVisible class is no added to the Fabric component again, to preserve backwards compatibility. Also fixing index file to export the types.", | ||
"type": "minor" | ||
} | ||
], | ||
"packageName": "office-ui-fabric-react", | ||
"email": "[email protected]" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/office-ui-fabric-react/src/components/Fabric/Fabric.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import * as React from 'react'; | ||
import * as renderer from 'react-test-renderer'; | ||
import { Fabric } from './Fabric'; | ||
|
||
describe('Fabric', () => { | ||
it('renders correctly', () => { | ||
const component = renderer.create( | ||
<Fabric>test</Fabric> | ||
); | ||
const tree = component.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
}); |
42 changes: 39 additions & 3 deletions
42
packages/office-ui-fabric-react/src/components/Fabric/Fabric.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,63 @@ | ||
import * as React from 'react'; | ||
import { | ||
BaseComponent, | ||
createRef, | ||
customizable, | ||
getNativeProps, | ||
divProperties, | ||
classNamesFunction | ||
classNamesFunction, | ||
getWindow, | ||
isDirectionalKeyCode | ||
} from '../../Utilities'; | ||
import { getStyles } from './Fabric.styles'; | ||
import { IFabricProps, IFabricStyleProps, IFabricStyles } from './Fabric.types'; | ||
|
||
const getClassNames = classNamesFunction<IFabricStyleProps, IFabricStyles>(); | ||
|
||
@customizable('Fabric', ['theme']) | ||
export class Fabric extends BaseComponent<IFabricProps, {}> { | ||
export class Fabric extends BaseComponent<IFabricProps, { | ||
isFocusVisible: boolean; | ||
}> { | ||
private _rootElement = createRef<HTMLDivElement>(); | ||
|
||
constructor(props: IFabricProps) { | ||
super(props); | ||
this.state = { isFocusVisible: false }; | ||
} | ||
|
||
public render() { | ||
const classNames = getClassNames(getStyles, this.props as IFabricStyleProps); | ||
const classNames = getClassNames(getStyles, | ||
{ | ||
...this.props as IFabricStyleProps, | ||
...this.state | ||
}); | ||
const divProps = getNativeProps(this.props, divProperties); | ||
|
||
return ( | ||
<div | ||
{ ...divProps } | ||
className={ classNames.root } | ||
ref={ this._rootElement } | ||
/> | ||
); | ||
} | ||
|
||
public componentDidMount(): void { | ||
const win = getWindow(this._rootElement.value); | ||
|
||
if (win) { | ||
this._events.on(win, 'mousedown', this._onMouseDown, true); | ||
this._events.on(win, 'keydown', this._onKeyDown, true); | ||
} | ||
} | ||
|
||
private _onMouseDown = (ev: MouseEvent): void => { | ||
this.setState({ isFocusVisible: false }); | ||
} | ||
|
||
private _onKeyDown = (ev: KeyboardEvent): void => { | ||
if (isDirectionalKeyCode(ev.which)) { | ||
this.setState({ isFocusVisible: true }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/office-ui-fabric-react/src/components/Fabric/__snapshots__/Fabric.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Fabric renders correctly 1`] = ` | ||
<div | ||
className= | ||
ms-Fabric | ||
{ | ||
-moz-osx-font-smoothing: grayscale; | ||
-webkit-font-smoothing: antialiased; | ||
color: #333333; | ||
font-family: 'Segoe UI', 'Segoe UI Web (West European)', 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Roboto', 'Helvetica Neue', sans-serif; | ||
font-size: 14px; | ||
font-weight: 400; | ||
} | ||
& button { | ||
font-family: inherit; | ||
} | ||
& input { | ||
font-family: inherit; | ||
} | ||
& textarea { | ||
font-family: inherit; | ||
} | ||
button { | ||
overflow: visible; | ||
} | ||
> | ||
test | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './Fabric'; | ||
export * from './Fabric.types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { isDirectionalKeyCode } from './keyboard'; | ||
import { KeyCodes } from './KeyCodes'; | ||
|
||
describe('isDirectionalKeyCode', () => { | ||
it('can return the expected value', () => { | ||
isDirectionalKeyCode(KeyCodes.up); | ||
isDirectionalKeyCode(KeyCodes.enter); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { KeyCodes } from './KeyCodes'; | ||
|
||
const DirectionalKeyCodes: { [key: number]: number } = { | ||
[KeyCodes.up]: 1, | ||
[KeyCodes.down]: 1, | ||
[KeyCodes.left]: 1, | ||
[KeyCodes.right]: 1, | ||
[KeyCodes.home]: 1, | ||
[KeyCodes.end]: 1, | ||
[KeyCodes.tab]: 1, | ||
[KeyCodes.pageUp]: 1, | ||
[KeyCodes.pageDown]: 1 | ||
}; | ||
|
||
/** | ||
* Returns true if the keycode is a directional keyboard key. | ||
*/ | ||
export function isDirectionalKeyCode(which: number): boolean { | ||
return !!DirectionalKeyCodes[which]; | ||
} |