Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Dropdown): add upward prop #1603

Merged
merged 1 commit into from
Apr 21, 2017
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
14 changes: 14 additions & 0 deletions docs/app/Examples/modules/Dropdown/Usage/DropdownExampleUpward.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react'
import { Dropdown } from 'semantic-ui-react'

const options = [
{ key: 'new', text: 'New', value: 'new' },
{ key: 'save', text: 'Save as...', value: 'save' },
{ key: 'edit', text: 'Edit', value: 'edit' },
]

const DropdownExampleUpward = () => (
<Dropdown upward floating options={options} text='File' />
)

export default DropdownExampleUpward
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react'
import { Dropdown } from 'semantic-ui-react'

const options = [
{ key: 's', text: 'small', value: 's' },
{ key: 'm', text: 'medium', value: 'm' },
{ key: 'l', text: 'large', value: 'l' },
]

const DropdownExampleUpwardInline = () => (
<div>
I'd like a size{' '}
<Dropdown upward floating inline options={options} defaultValue='m' />
{' '}T-shirt, please.
</div>
)

export default DropdownExampleUpwardInline
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react'
import { Dropdown } from 'semantic-ui-react'

const options = [
{ key: 1, text: 'One', value: 1 },
{ key: 2, text: 'Two', value: 2 },
{ key: 3, text: 'Three', value: 3 },
]

const DropdownExampleUpwardSelection = () => (
<Dropdown upward search selection options={options} placeholder='Choose an option' />
)

export default DropdownExampleUpwardSelection
11 changes: 11 additions & 0 deletions docs/app/Examples/modules/Dropdown/Usage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ const DropdownUsageExamples = () => (
description='A dropdown item can be rendered differently inside the menu.'
examplePath='modules/Dropdown/Usage/DropdownExampleItemContent'
/>
<ComponentExample
title='Upward'
description='A dropdown can open its menu upward.'
examplePath='modules/Dropdown/Usage/DropdownExampleUpwardSelection'
/>
<ComponentExample
examplePath='modules/Dropdown/Usage/DropdownExampleUpwardInline'
/>
<ComponentExample
examplePath='modules/Dropdown/Usage/DropdownExampleUpward'
/>

</ExampleSection>
)
Expand Down
5 changes: 4 additions & 1 deletion src/modules/Dropdown/Dropdown.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface DropdownProps {
defaultSelectedLabel?: number | string;

/** Initial value or value array if multiple. */
defaultValue?: string | number | Array<number | string >;
defaultValue?: string | number | Array<number | string>;

/** A disabled dropdown menu or item does not allow user interaction. */
disabled?: boolean;
Expand Down Expand Up @@ -232,6 +232,9 @@ export interface DropdownProps {

/** Current value or value array if multiple. Creates a controlled component. */
value?: number | string | Array<number | string>;

/** A dropdown can open upward. */
upward: boolean;
}

interface DropdownComponent extends React.ComponentClass<DropdownProps> {
Expand Down
13 changes: 9 additions & 4 deletions src/modules/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ export default class Dropdown extends Component {
PropTypes.node,
]),

/** A dropdown can open upward. */
upward: PropTypes.bool,

/** Current value or value array if multiple. Creates a controlled component. */
value: PropTypes.oneOfType([
PropTypes.string,
Expand Down Expand Up @@ -1193,23 +1196,24 @@ export default class Dropdown extends Component {
button,
className,
compact,
disabled,
error,
fluid,
floating,
icon,
inline,
item,
labeled,
loading,
multiple,
pointing,
search,
selection,
simple,
loading,
error,
disabled,
scrolling,
simple,
tabIndex,
trigger,
upward,
} = this.props

// Classes
Expand Down Expand Up @@ -1237,6 +1241,7 @@ export default class Dropdown extends Component {
useKeyOnly(selection, 'selection'),
useKeyOnly(simple, 'simple'),
useKeyOnly(scrolling, 'scrolling'),
useKeyOnly(upward, 'upward'),

useKeyOrValueAndKey(pointing, 'pointing'),
className,
Expand Down
1 change: 1 addition & 0 deletions test/specs/modules/Dropdown/Dropdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ describe('Dropdown', () => {
common.propKeyOnlyToClassName(Dropdown, 'selection')
common.propKeyOnlyToClassName(Dropdown, 'simple')
common.propKeyOnlyToClassName(Dropdown, 'scrolling')
common.propKeyOnlyToClassName(Dropdown, 'upward')

common.propKeyOrValueAndKeyToClassName(Dropdown, 'pointing', [
'left', 'right', 'top', 'top left', 'top right', 'bottom', 'bottom left', 'bottom right',
Expand Down