-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ScrollView): add
interactive
prop to support for keyboard cont…
…rol (accessible) (#1791)
- Loading branch information
1 parent
cb497de
commit e265e4a
Showing
10 changed files
with
146 additions
and
25 deletions.
There are no files selected for viewing
7 changes: 4 additions & 3 deletions
7
...ges/dnb-design-system-portal/src/docs/uilib/components/fragments/scroll-view.md
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,13 +1,14 @@ | ||
--- | ||
title: 'ScrollView' | ||
description: 'ScrollView is a tiny helper component to allow Eufemia controlling the UX.' | ||
# showTabs: true | ||
description: 'ScrollView is a tiny helper component helping the user controlling overflowing content horizontally or vertically' | ||
showTabs: true | ||
status: null | ||
hideTabs: | ||
- title: Events | ||
- title: Properties | ||
--- | ||
|
||
import ScrollViewInfo from 'Docs/uilib/components/fragments/scroll-view/info' | ||
import ScrollViewDemos from 'Docs/uilib/components/fragments/scroll-view/demos' | ||
|
||
<ScrollViewInfo /> | ||
<ScrollViewDemos /> |
27 changes: 27 additions & 0 deletions
27
...ges/dnb-design-system-portal/src/docs/uilib/components/fragments/scroll-view/Examples.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,27 @@ | ||
/** | ||
* UI lib Component Example | ||
* | ||
*/ | ||
|
||
import React from 'react' | ||
import ComponentBox from 'dnb-design-system-portal/src/shared/tags/ComponentBox' | ||
import { ScrollView } from '@dnb/eufemia/src/fragments' | ||
|
||
export const ScrollViewInteractive = () => ( | ||
<ComponentBox> | ||
<ScrollView interactive={true} style={{ maxHeight: '10rem' }}> | ||
<div | ||
style={{ | ||
minHeight: 800, | ||
display: 'flex', | ||
flexDirection: 'column', | ||
justifyContent: 'flex-end', | ||
background: | ||
'linear-gradient(rgba(255,0,0,1) 0%, rgba(255,154,0,1) 10%, rgba(208,222,33,1) 20%, rgba(79,220,74,1) 30%, rgba(63,218,216,1) 40%, rgba(47,201,226,1) 50%, rgba(28,127,238,1) 60%, rgba(95,21,242,1) 70%, rgba(186,12,248,1) 80%, rgba(251,7,217,1) 90%, rgba(255,0,0,1) 100%) 0 0/100% 200%', | ||
}} | ||
> | ||
large content | ||
</div> | ||
</ScrollView> | ||
</ComponentBox> | ||
) |
17 changes: 17 additions & 0 deletions
17
...b-design-system-portal/src/docs/uilib/components/fragments/scroll-view/demos.md
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,17 @@ | ||
--- | ||
showTabs: true | ||
--- | ||
|
||
import { | ||
ScrollViewInteractive, | ||
} from 'Docs/uilib/components/fragments/scroll-view/Examples' | ||
|
||
## Demos | ||
|
||
### Keyboard support | ||
|
||
When used for regular content, it should be possible for the user to user their keyboard to controll the scrollposition. | ||
|
||
You can enable keyboard support with the `interactive` prop. | ||
|
||
<ScrollViewInteractive /> |
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
10 changes: 10 additions & 0 deletions
10
...ign-system-portal/src/docs/uilib/components/fragments/scroll-view/properties.md
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,10 @@ | ||
--- | ||
showTabs: true | ||
--- | ||
|
||
## Properties | ||
|
||
| Properties | Description | | ||
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------ | | ||
| `interactive` | _(optional)_ set to `true` to make the content accessible to keyboard navigation. Defaults to `false`. | | ||
| [Space](/uilib/components/space/properties) | _(optional)_ spacing properties like `top` or `bottom` are supported. | |
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
46 changes: 46 additions & 0 deletions
46
packages/dnb-eufemia/src/fragments/scroll-view/__tests__/ScrollView.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,46 @@ | ||
import React from 'react' | ||
import { render } from '@testing-library/react' | ||
import ScrollView from '../ScrollView' | ||
|
||
describe('ScrollView', () => { | ||
it('should contain children content', () => { | ||
render(<ScrollView>overflow content</ScrollView>) | ||
|
||
const element = document.querySelector('.dnb-scroll-view') | ||
|
||
expect(element.textContent).toBe('overflow content') | ||
}) | ||
|
||
it('should set tabindex when interactive is set', () => { | ||
render(<ScrollView interactive>overflow content</ScrollView>) | ||
|
||
const element = document.querySelector('.dnb-scroll-view') | ||
const attributes = Array.from(element.attributes).map( | ||
(attr) => attr.name | ||
) | ||
|
||
expect(attributes).toEqual(['class', 'tabindex']) | ||
}) | ||
|
||
it('should include custom classes', () => { | ||
render( | ||
<ScrollView className="custom-class">overflow content</ScrollView> | ||
) | ||
|
||
const element = document.querySelector('.dnb-scroll-view') | ||
expect(Array.from(element.classList)).toEqual([ | ||
'dnb-scroll-view', | ||
'custom-class', | ||
]) | ||
}) | ||
|
||
it('should support spacing', () => { | ||
render(<ScrollView top="large">overflow content</ScrollView>) | ||
|
||
const element = document.querySelector('.dnb-scroll-view') | ||
expect(Array.from(element.classList)).toEqual([ | ||
'dnb-scroll-view', | ||
'dnb-space__top--large', | ||
]) | ||
}) | ||
}) |
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