Giter VIP home page Giter VIP logo

checkbox's People

Contributors

aaa70 avatar afc163 avatar ambientlighter avatar benjycui avatar bingqichen avatar crazyair avatar dependabot-preview[bot] avatar dependabot[bot] avatar ilnicki avatar jaimemendozadev avatar kanweiwei avatar lgtm-com[bot] avatar li-jia-nan avatar linxianxi avatar liuchao233 avatar madccc avatar nataliiakononikhina avatar ne-smalltown avatar paranoidjk avatar peachscript avatar raohai avatar sarehag avatar superraytin avatar swistak35 avatar wangxingkang avatar xinpingwang 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

checkbox's Issues

[feature]: need an event object in onChange handler

Someone may want to mimic windows folder selection. For example, select multiple items hold down the CTRL key,or select a few items at the same time hold down the SHIFT key. To do that I need an event object in onChange handler so that i can get some attributes like crtlKey and shiftKey of e.nativeEvent.

related ant-design/ant-design#9368

Checkbox Event Type Error

Issue

  • happens in e.target.checked: Property 'checked' does not exist on type 'EventTarget'.
<Checkbox checked={x} onChange={(e) => setX(e.target.checked)} />

Suggestion

  • in index.d.ts
export interface Props {
  onChange?: (e: Event) => void;
}
  • to sth like following
interface Target extends Props {
  checked: boolean;
}

interface ChangeEvent {
  target: Target;
  stopPropagation: () => void;
  preventDefault: () => void;
  nativeEvent: Object;
}

export interface Props {
  onChange?: (e: ChangeEvent) => void;
}

onChange 传参 Event 而不直接是 checked 的原因?

请教一下

目前使用 Event 挺好的。我只是想请教作者们在回调时传递 Event 对象而不是直接传递 e.target.checked 的原因

<Checkbox onChange={function(checked){

}} />

因为我在实现一些组件时会考虑如下2点:

  • 传 Event 可维护性和适用场景更好
  • 直接传 checked 所有组件 onChange 回调参数格式一致,能保持同一家族组件接口一致。

Invalid prop `checked` supplied to `Checkbox`

Unnecessary Warning

my code:

import CheckBox from 'rc-checkbox'; 
...
 <CheckBox
          color="#29363d"
          checked={historyItem.pdf}
          className="checkbox-design"
        />

When i load this compoent is shows Warning as below,

Warning: Failed prop type: Invalid prop 'checked' supplied to 'Checkbox'. in Checkbox (created by xyz)

i hope this will help...

tabIndex

Hello rc-checkbox auther,
Thank you so much for good component.

Do you have a plan to support tabIndex?
I'd like to ignore the checkbox during tab key jumping.

Thanks,

no lib directory after npm install

Installed from antd and the rc-checkbox is missing lib directory. Can you kindly look into this issue? Possibly due to npm ignore properties.

Thank you!

expose `currentTarget` in `handleChange`

Happy to send a PR :)

From react/flow docs:

Note: To get the element instance, like HTMLButtonElement in the example above, it is a common mistake to use event.target instead of event.currentTarget. The reason why you want to use event.currentTarget is that event.target may be the wrong element due to event propagation.

Relevant code:

  handleChange = (e) => {
    const { props } = this;
    if (props.disabled) {
      return;
    }
    if (!('checked' in props)) {
      this.setState({
        checked: e.target.checked,
      });
    }
    props.onChange({
+     currentTarget: e.currentTarget,
      target: {
        ...props,
        checked: e.target.checked,
      },
      stopPropagation() {
        e.stopPropagation();
      },
      preventDefault() {
        e.preventDefault();
      },
      nativeEvent: e.nativeEvent,
    });
  };

去除 label 功能

和原生 checkbox 一致

label 由用户自己控制

<Checkbox /><label>q</labe>

Error with React 16.3.2

Checkbox.js:110 Uncaught TypeError: Cannot read property 'string' of undefined

wrong work with PropTypes

about useMergedState(null,{...})

/** We only think `undefined` is empty */
function hasValue(value: any) {
  return value !== undefined;
}

I think using useMergedState is unreasonable

<Checkbox checked={null} defaultChecked={true} onChange={onChange}>
    Checkbox
</Checkbox>
{/* Correct */}
<input type="checkbox" checked={null} defaultChecked />

Show different results

Prop "title" is ignored

If I pass the title as a prop to the Checkbox component, it will be removed before passing it to the HTML attribute title.
Like the data-*, aria-* and role attributes it should be passed over to the HTML.

E.g.
<Checkbox title="Dr. Prof." />
should be mapped to
<input type="checkbox" title="Dr. Prof." />.

Unusable typescript typing

Current index.d.ts declares every prop as required. This is not actually true and completely breaks ability of the component being used with ts. I propose to make everything optional. It should not break any compatibility while make the component easier to use. Also it needs some improvements with type clarification but it can break some things.

Does not work with browser-sync

Browser sync injects a extra blur(); focus(); to checkboxes and radios at the addEventListener level.
Resulting in the following sequence of events:

<Checkbox 
  checked={false}
  onBlur={e => console.log("blur", e.target.checked)}
  onFocus={e => console.log("focus", e.target.checked)}
  onChange={e => console.log("focus", e.target.checked)}
/>

- focus,  false
- blur,   true (added by browsersync)
- focus,  false (added by browsersync)
- change, false

When the onChange is called the e.target.chacked is no longer trueand thus the checkbox never toggles its state.

This only fails in 1.3.4 since the addition of onBlur and onFocus that change the component state.
If I comment out the setState lines from onBlur and onFocus it works correctly (albeit isFocused support is lost ofc)

Bug: Defaulted props not used in onChange callback

Issue

The props that have default values, are not used in the event.target from onChange

v2.3.2 functionality

In v2.3.2 the props were defaulted via defaultProps;

checkbox/src/index.jsx

Lines 6 to 18 in 22992a5

static defaultProps = {
prefixCls: 'rc-checkbox',
className: '',
style: {},
type: 'checkbox',
defaultChecked: false,
onFocus() {},
onBlur() {},
onChange() {},
onKeyDown() {},
onKeyPress() {},
onKeyUp() {},
};

Which meant that in the onChange target would use these defaulted props;

checkbox/src/index.jsx

Lines 59 to 63 in 22992a5

onChange({
target: {
...this.props,
checked: e.target.checked,
},

v3.0.0 functionality

However in v3.0.0, the props are only defaulted in the destructuring;

checkbox/src/index.tsx

Lines 30 to 40 in cfdcf03

const {
prefixCls = 'rc-checkbox',
className,
style,
checked,
disabled,
defaultChecked = false,
type = 'checkbox',
onChange,
...inputProps
} = props;

Which means the defaulted values are not used for target;

checkbox/src/index.tsx

Lines 71 to 75 in cfdcf03

onChange?.({
target: {
...props,
checked: e.target.checked,
},

Summary

in v2.3.2; <Checkbox onChange={(e) => console.log(e.target.type)} {...otherProps} />; will log "checkbox"
in v3.0.0; <Checkbox onChange={(e) => console.log(e.target.type)} {...otherProps} />; will log undefined

Change the color?

How can I change the default blue color? I don't see this documented anywhere.

examples/simple.js checked checkbox should use "defaultChecked" props

examples/simple.js:

<Checkbox
  checked
  onChange={onChange}
  disabled={this.state.disabled}
/>

The "checked" props will cause the checkbox component can not response to the click event,
in the Checkbox.jsx source code below:

handleChange(e) {
  const checked = e.target.checked;
  if (!('checked' in this.props)) {
    this.setState({
    checked: checked ? 1 : 0,
    });
}

"checked" should be "defaultChecked".

Version 2.3 does not have Typescript types included

Hello,

We have tried to upgrade to the latest version. Unfortunately, our builds are crashing as the type declarations are no longer present in the package. Could you please provide them back?

Thank you for the library and its maintenance.

Select all

I have a list of checkboxes, is it possible to use the event on a button to select them all?

Thank you.

Checkbox strips both synthetic & native event object off of all of their useful properties in `handleChange`

  • Synthetic events are a superset of Native events and IMO Synthetic events should be preferred.
  • Users wanting to use native events can always choose event.nativeEvent
  • This code is suppressing both synthetic & native event object, which means event.datasets or event.nativeEvent.target.dataset can't be used anymore.
  • This takes away the ability to access other DOM APIs even.
this.props.onChange({
      target: {
        ...this.props,
        checked: e.target.checked,
      },
      stopPropagation() {
        e.stopPropagation();
      },
      preventDefault() {
        e.preventDefault();
      },
    });

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.