
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
@solid-aria/button
Advanced tools
Buttons allow users to perform an action or to navigate to another page. They have multiple styles for various needs, and are ideal for calling attention to where a user needs to do something in order to move forward in a flow.
npm install @solid-aria/button
# or
yarn add @solid-aria/button
# or
pnpm add @solid-aria/button
createButton
Provides the behavior and accessibility implementation for a button component. Handles mouse, keyboard, and touch interactions, focus behavior, and ARIA props for both native button elements and custom element types.
On the surface, building a custom styled button seems simple. However, there are many cross browser inconsistencies in interactions and accessibility features to consider. createButton
handles all of these interactions for you, so you can focus on the styling.
<button>
support<a>
and custom element type support via ARIASpace
and Enter
keysBy default, createButton
assumes that you are using it with a native <button>
element.
import { AriaButtonProps, createButton } from "@solid-aria/button";
function Button(props: AriaButtonProps) {
let ref: HTMLButtonElement | undefined;
const { buttonProps } = createButton(props, () => ref);
return (
<button {...buttonProps} ref={ref}>
{props.children}
</button>
);
}
function App() {
return <Button onPress={() => alert("Button pressed!")}>Test</Button>;
}
Sometimes you might need to use an element other than a native <button>
. createButton
supports this via the elementType
prop. When used with an element other than a native button, createButton
automatically applies the necessary ARIA roles and attributes to ensure that the element is exposed to assistive technology as a button.
In addition, this example shows usage of the isPressed
value returned by createButton
to properly style the button's active state. You could use the CSS :active
pseudo class for this, but isPressed
properly handles when the user drags their pointer off of the button, along with keyboard support and better touch screen support.
import { AriaButtonProps, createButton } from "@solid-aria/button";
import { mergeProps } from "solid-js";
function Button(props: AriaButtonProps<"span">) {
let ref: HTMLButtonElement | undefined;
const createButtonProps = mergeProps({ elementType: "span" }, props);
const { buttonProps, isPressed } = createButton(createButtonProps, () => ref);
return (
<span
{...buttonProps}
style={{
background: isPressed() ? "darkgreen" : "green",
color: "white",
padding: "10px",
cursor: "pointer",
"user-select": "none",
"-webkit-user-select": "none"
}}
ref={ref}
>
{props.children}
</span>
);
}
function App() {
return <Button onPress={() => alert("Button pressed!")}>Test</Button>;
}
createToggleButton
Provides the behavior and accessibility implementation for a toggle button component. ToggleButtons allow users to toggle a selection on or off, for example switching between two states or modes.
Toggle buttons are similar to action buttons, but support an additional selection state that is toggled when a user presses the button. There is no built-in HTML element that represents a toggle button, so Solid Aria implements it using ARIA attributes.
<button>
, <a>
, and custom element type supportSpace
and Enter
keysBy default, createToggleButton
assumes that you are using it with a native <button>
element. You can use a custom element type by passing the elementType
prop to createToggleButton
. See the createButton
docs for an example of this.
The following example shows how to use the createToggleButton
to build a toggle button. The toggle state is used to switch between a green and blue background when unselected and selected respectively. In addition, the isPressed
state is used to adjust the background to be darker when the user presses down on the button.
import { AriaToggleButtonProps, createToggleButton } from "@solid-aria/button";
function ToggleButton(props: AriaToggleButtonProps) {
let ref: HTMLButtonElement | undefined;
const { buttonProps, isPressed, state } = createToggleButton(props, () => ref);
return (
<button
{...buttonProps}
style={{
background: isPressed()
? state.isSelected()
? "darkblue"
: "darkgreen"
: state.isSelected()
? "blue"
: "green",
color: "white",
padding: "10px",
cursor: "pointer",
"user-select": "none",
"-webkit-user-select": "none",
border: "none"
}}
ref={ref}
>
{props.children}
</button>
);
}
function App() {
return <ToggleButton>Test</ToggleButton>;
}
All notable changes are described in the CHANGELOG.md file.
FAQs
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.