Giter VIP home page Giter VIP logo

dropdown's Introduction

rc-dropdown

react dropdown component

NPM version build status Test coverage Dependencies DevDependencies npm download bundle size dumi

Screenshot

Example

online example: http://react-component.github.io/dropdown/examples/

install

rc-dropdown

Usage

var Dropdown = require('rc-dropdown');
// use dropdown

API

props

                                       
name type default description
overlayClassName String additional css class of root dom node
openClassName String`${prefixCls}-open`className of trigger when dropdown is opened
prefixCls String rc-dropdown prefix class name
transitionName String dropdown menu's animation css class name
animation String part of dropdown menu's animation css class name
placement String bottomLeft Position of menu item. There are: top, topCenter, topRight, bottomLeft, bottom, bottomRight
onVisibleChange Function call when visible is changed
visible boolean whether tooltip is visible
defaultVisible boolean whether tooltip is visible initially
overlay rc-menu rc-menu element
onOverlayClick function(e) call when overlay is clicked
minOverlayWidthMatchTrigger booleantrue (false when set alignPoint)whether overlay's width must not be less than trigger's
getPopupContainer Function(menuDOMNode): HTMLElement () => document.body Where to render the DOM node of dropdown

Note: Additional props are passed into the underlying rc-trigger component. This can be useful for example, to display the dropdown in a separate portal-driven window via the getDocument() rc-trigger prop.

Development

npm install
npm start

Test Case

npm test
npm run chrome-test

Coverage

npm run coverage

open coverage/ dir

License

rc-dropdown is released under the MIT license.

dropdown's People

Contributors

afc163 avatar aight8 avatar azu avatar cagen avatar dbsds avatar dependabot-preview[bot] avatar dependabot-support avatar eternalsky avatar h-a-n-a avatar heracek avatar honzahruby avatar howel52 avatar hungdev avatar ilkaydnc avatar ldabiralai avatar lgtm-com[bot] avatar madccc avatar menberg avatar muxinfeng avatar ousiri avatar rinick avatar shaodahong avatar tyrasd avatar viniciusrmcarneiro avatar warmhug avatar xettri avatar yesmeck avatar yiminghe avatar zombiej avatar ztplz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dropdown's Issues

ChainAlert: new npm maintainer has published version 3.2.1 of package rc-dropdown

Dear rc-dropdown maintainers,
Thank you for your contribution to the open-source community.

This issue was automatically created to inform you a new npm maintainer has published version 3.2.1 of rc-dropdown.

New Maintainers:

Our service monitors the open-source ecosystem and informs popular packages' owners in case of potentially harmful activity.
If you find this behavior legitimate, kindly close and ignore this issue. Read more

badge

Should this package have a new release?

Used packages have new releases which fix a lot of bugs. Should react-component/dropdown have a release too?

For example, the /trigger package
image

This is /dropdown latest release 7 months ago:
image

Type definitions not found

What the title says
image

Downloaded the package using npm.
I can see that there are type definitions supplied with the package on git, but they're missing in the node_modules dir

Am I missing something?

Accessibility is half-baked

Hi, I see there are some ARIA attributes in place for menus. However, the dropdown can't be navigated with the keyboard, and the trigger button is not associated with the menu.

First, the button needs to be bound to the menu–this can be done with aria-controls="theMenuID", aria-haspopup="true", and aria-expanded="true | false".

When the dropdown opens, focus should be sent to the first item (which needs tabindex="0") instead of the unordered list which has tabindex. Using the roving tabindex technique, only one item can be tabbable at a time when the menu is open. You've already got aria-activedescendant working, so the tabindex and focus management portions will get you part of the way there!

Hooking up the escape key to close the menu would be a nice addition, too.

Ability to modify builtinPlacements

The current builtinPlacements are fixed. Those are nice preset, but I trying to remove the 4px spacing to have a seamless contact between the trigger and the dropdown.

edit: this can be solves with css.

自动计算弹出菜单的宽度

如果不设置,菜单宽度按以下原则计算:

  1. 取触发元素的宽度
  2. 取菜单文字的最大宽度
  3. 取两者的大值

这样如何?

Placement prop not working

Passing placement prop doesn't change the class name.
Its always the default bottomRight

"dependencies": { "rc-dropdown": "^2.4.1" }

<Dropdown overlay={menu} placement="topRight"> <button> Actions </button> </Dropdown>

visible is false but still have class “rc-dropdown-open”

file1

  import Button from 'rc-button';
  const overlay = () => {
   return (
    <Button onClick={props.onHandle}> close </Button>
   )
 }
export default overlay

file2

 import Dropdown from 'rc-dropdown';
import Overlay from './overlay'
  const drop = () => {
  const  [visible, setVisible] = useState(false)
    return (
      <Dropdown
        overlay={<OverLay onHandle={setVisible(false}} />}
        visible={visible}
      >
        <Button> show </Button>
      </Dropdown>
    )
  }
export default drop

when click button close , but the Button class still have rc-dropdown-open

The dropdown can't be closed while click document if set trigger="click"

<Dropdown overlay={menu4} trigger="click">
          <button className="btn btn-info btn-sm">
            点击触发 <i className="glyph-icon glyph-arrow-down"></i>
          </button>
        </Dropdown>

it throw error, Uncaught TypeError: this.popupInstance.getPopupDomNode is not a function
Note: first click trigger button, it works fine. click trigger button repeat twice +, it will throw error.

Pass dropdown visible state to overlay

Hi, When I pass dropdown visible state to overlay and set the trigger to hover, the overlay prop is not update correctly.
Demo

// You should fork and save if you had updated this CodePend and want to send it to others.
// Note: antd.locales are only support by `dist/antd`
const { Dropdown } = antd;

class Div extends React.Component {
  componentDidMount () {
    console.log('overlay mount', this.props.visible)  
  }
  
  componentDidUpdate () {
    console.log('overlay update', this.props.visible)  
  }
  
  render () {
    return <div className='overlay-container'>Overlay</div>
  }
}

class Test extends React.Component {
  constructor (props) {
    super(props)
    this.state = {
      visible: false
    }
    this.handleVisibleChange = this.handleVisibleChange.bind(this)
  }
  
  handleVisibleChange (visible) {
    console.log('visible change', visible)
    this.setState({ visible })
  }
  
  render () {
    return (
      <div>
        <Dropdown
          placement='bottomLeft'
          trigger={['click']}
          onVisibleChange={this.handleVisibleChange}
          overlay={<Div visible={this.state.visible} />}
        >
          <span className='trigger-text'>Click Text</span>
        </Dropdown>
        <Dropdown
          placement='bottomRight'
          trigger={['hover']}
          mouseEnterDelay={0}
          onVisibleChange={this.handleVisibleChange}
          overlay={<Div visible={this.state.visible} />}
        >
          <span>Hover Text</span>
        </Dropdown>
      </div>
      
    )
  }
}

ReactDOM.render(
  <Test />
, mountNode);

When the mouse leave the Trigger, the output of the console is like this:
image
overlay is updated before the visible has changed, and the value is true not false

And it also related to the mouseEnterDelay prop. When mouseEnterDelay is not set to 0 (0 is the default prop value of rc-trigger), the result is different:
image
overlay is updated before the visible has changed too, but when the next enter event trigger, the overlay prop updated twice.

If the trigger is set to 'click',everything works fine:
image

Key control for web accessibility

Is there any way to controll this dropdown by keyboard control?

For example, press enter to trigger dropdown and press arrow up or arrow down to change focused item.

Thanks

setting hideAction = 'mouseLeave' unexpectedly hides the menu when the mouse leaves the trigger control and enters the menu area

I am using the latest 1.4.10 version of the dropdown.

I would like the dropdown to hide when the user moves the mouse off the menu or if the user clicks outside of the menu. Setting hideAction to 'mouseLeave' seemed to be the way to accomplish this.

Setting hideAction results in the menu hiding when the user moves from the trigger button to the menu.

Is there another prop that I should be using?

To see the behavior, modify the examples/simple.js in the repo
~ add hideAction prop to the Dropdown as in below.

ReactDOM.render(<div style={{ margin: 20 }}>

open
, document.getElementById('__react-content'));

Dynamic menu

I have to add/remove menu item based on some conditions so how can I achieve it ??

IE8 support fail in ver. 1.4.7

lib/index.js

'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _Dropdown = require('./Dropdown');

var _Dropdown2 = _interopRequireDefault(_Dropdown);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

exports.default = _Dropdown2.default;
module.exports = exports['default'];

1.4.6 hasn't this problem.

Last commit of dependency package (rc-trigger) breaks the dropdown

Hi,
It seems that you have a dependency on https://github.com/react-component/trigger, and the following commit breaks the dropdown (namely prevents it from opening, the div with the dropdown gets position 'absolute' and style.top/left of '-9999px'.
react-component/trigger@6ea92c7

At the same time the requirement for rc-trigger dependency is "1.x", which causes npm to install the latest (broken) version 1.8.2.
I suggest updating rc-trigger dependency to "1.8.1", as this was the last working version and fixing the rc-trigger.
Should I create a pull request?
Thanks! :)

minOverlayWidthMatchTrigger为true时,dropdown定位不准确

在Trigger的宽度大于overlay的宽度的情形下,当minOverlayWidthMatchTrigger为true时(rc-dropdown的默认值)且 placement 不是靠左的时候,第一次显示dropdown的位置会偏移。(再显示一次就会正常了)

例子:
https://codepen.io/anon/pen/aymyVB?editors=001

我找到的可能的原因是dropdown是先按照原始宽度做的align,然后再根据Trigger的宽度去改变dropdown的宽度,但dropdown本身却没有重新align:
https://github.com/react-component/dropdown/blob/master/src/Dropdown.jsx#L104

  1. 第一次显示
    image

  2. 宽度调整
    image

  3. 最终显示
    image

left equal to 0

I write a example contrast to the official example, but got this layout
image

image

Dropdown should be directly aware of overlay clicks.

The current suggested implementation requires the Menu component to notify the Dropdown component when someone clicks on the menu via a higher-level wrapper component. This results in a lot of boilerplate just for the Dropdown to react to Menu.Item clicks. Once you pass the Menu in the Dropdown's overlay prop, the Dropdown should be self-sufficient. Really, once the Menu is passed to the Dropdown as its overlay prop, the Dropdown should be directly aware of clicks on its own overlay.

I suggest the simple addition of Dropdown.props.onOverlayClick, a function which gets fired whenever the overlay is actually clicked. I've submitted a pull request for it here: #20.

A future enhancement could be to pass data on exactly which Menu.Item was clicked, allowing the Dropdown to make smart decisions on how to respond to the event.

Dropdown is causing Input to lose focus when the menu opens @3.2.3

Hello, here's how im using the Dropdown from antd:

const [menuVisible, setMenuVisible] = useState(false);

const onInputFocus = useCallback(() => setMenuVisible(true), []);
const onInputBlur = useCallback(() => setMenuVisible(false), []);

<Dropdown overlay={OptionMenu} visible={menuVisible}>
  <Input
    className={styles.input}
    onFocus={onInputFocus}
    onBlur={onInputBlur}
  />
</Dropdown>

And I can confirm that every time the Dropdown opens, the onBlur on Input is triggered.

The issue is introduced in version @3.2.3, and I reverted back to use version @3.2.2 and the issue is fixed.

Adding additional props from rc-trigger will break current typescript declare

Hi, I currently want to use forceRender prop from rc-trigger in my dropdown. However, when I add the props to my current dropdown, typescript will cause errors because forceRender is not a prop of the dropdown component.

Screen Shot 2020-04-09 at 11 15 30
In the typescript, I just wonder why do we only Pick 'getPopupContainer' | 'children' from TriggerProps ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.