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

Button element does not pass "label" property correctly #528

Open
talkingtab opened this issue Jan 17, 2025 · 0 comments
Open

Button element does not pass "label" property correctly #528

talkingtab opened this issue Jan 17, 2025 · 0 comments

Comments

@talkingtab
Copy link

currently the code in Button.tsx is

export function Button({ onClick, settings, label }: ButtonProps) {
  const store = useStoreContext()
  return (
    <Row>
      <StyledButton disabled={settings.disabled} onClick={() => onClick(store.get)}>
        {label}
      </StyledButton>
    </Row>
  )
}

But when called

useControls({red: button(onChange) {label: "blue"} )

The value "blue" is passed to Button() in settings. So {settings.label === "blue"} and label === "red".
The button shows "red" and ignores the parameter.

In order to support both cases, a function similar to ButtonGroup().getOpts() needs to be added to override label with {settings.label}. Je ne parle pas typescript, but I think the idea is the same.

const getOpts = ({ label: _label, opts: _opts }: ButtonGroupInternalOpts) => {
  let label = typeof _label === 'string' ? (_label.trim() === '' ? null : _label) : _label
  let opts = _opts
  if (typeof _opts.opts === 'object') {
    if (opts.label !== undefined) {
      label = _opts.label as any
    }
    opts = _opts.opts
  }

  return { label, opts: opts as ButtonGroupOpts }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant