Skip to content

Select Control

Elementor Core BasicSelect Control

Elementor select control displays a simple select box field. It accepts an array in which the key is the option value and the value is the option name.

The control is defined in Control_Select class which extends Base_Data_Control class.

When using this control, the type should be set to \Elementor\Controls_Manager::SELECT constant.

Arguments

NameTypeDefaultDescription
typestringselectThe type of the control.
labelstringThe label that appears above of the field.
descriptionstringThe description that appears below the field.
show_labelbooltrueWhether to display the label.
label_blockboolfalseWhether to display the label in a separate line.
separatorstringdefaultSet the position of the control separator. Available values are default, before and after. default will hide the separator, unless the control type has specific separator settings. before / after will position the separator before/after the control.
optionsarrayAn array of key => value pairs: [ 'key' => 'value', ... ]
groupsarrayAn array of grouped options.
defaultstringThe field default value.

Return Value

(string) The selected option value.

Usage

php
<?php
class Elementor_Test_Widget extends \Elementor\Widget_Base {

	protected function register_controls(): void {

		$this->start_controls_section(
			'style_section',
			[
				'label' => esc_html__( 'Style', 'textdomain' ),
				'tab' => \Elementor\Controls_Manager::TAB_STYLE,
			]
		);

		$this->add_control(
			'border_style',
			[
				'label' => esc_html__( 'Border Style', 'textdomain' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'default' => 'solid',
				'options' => [
					'' => esc_html__( 'Default', 'textdomain' ),
					'none' => esc_html__( 'None', 'textdomain' ),
					'solid'  => esc_html__( 'Solid', 'textdomain' ),
					'dashed' => esc_html__( 'Dashed', 'textdomain' ),
					'dotted' => esc_html__( 'Dotted', 'textdomain' ),
					'double' => esc_html__( 'Double', 'textdomain' ),
				],
				'selectors' => [
					'{{WRAPPER}} .your-class' => 'border-style: {{VALUE}};',
				],
			]
		);

		$this->add_control(
			'custom_animation',
			[
				'label' => esc_html__( 'Animation', 'textdomain' ),
				'type' => Controls_Manager::SELECT,
				'groups' => [
					[
						'label' => esc_html__( 'None', 'textdomain' ),
						'options' => [
							'' => esc_html__( 'None', 'textdomain' ),
						],
					],
					[
						'label' => esc_html__( 'Slide', 'textdomain' ),
						'options' => [
							'slide-from-right' => esc_html__( 'Slide In Right', 'textdomain' ),
							'slide-from-left' => esc_html__( 'Slide In Left', 'textdomain' ),
							'slide-from-top' => esc_html__( 'Slide In Up', 'textdomain' ),
							'slide-from-bottom' => esc_html__( 'Slide In Down', 'textdomain' ),
						],
					],
					[
						'label' => esc_html__( 'Zoom', 'textdomain' ),
						'options' => [
							'grow' => esc_html__( 'Grow', 'textdomain' ),
							'shrink' => esc_html__( 'Shrink', 'textdomain' ),
							'zoom-in' => esc_html__( 'Zoom In', 'textdomain' ),
							'zoom-out' => esc_html__( 'Zoom Out', 'textdomain' ),
						],
					],
				],
				'prefix_class' => 'custom-animation-',
			]
		);

		$this->end_controls_section();

	}

	protected function render(): void {
		$settings = $this->get_settings_for_display();
		?>
		<div class="your-class">
			...
		</div>
		<?php
	}

	protected function content_template(): void {
		?>
		<div class="your-class">
			...
		</div>
		<?php
	}

}